package com.jwsoft.manager.core.integration.individuation.impl;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.IdcardUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bifang.engine.assistant.core.annotation.ApiService;
import com.bifang.engine.assistant.core.annotation.OpApi;
import com.bifang.engine.assistant.core.enums.AuthStatusEnum;
import com.bifang.engine.assistant.core.enums.BoolEnum;
import com.bifang.engine.assistant.core.enums.FuncTypeEnum;
import com.bifang.engine.assistant.core.exception.AppException;
import com.bifang.module.base.common.vo.common.CommonVO;
import com.bifang.module.base.common.vo.dict.DictQueryVO;
import com.bifang.module.base.common.vo.dict.DictVO;
import com.bifang.module.base.common.vo.dict.SelectVO;
import com.bifang.module.base.core.integration.CommonIntegration;
import com.bifang.module.base.core.integration.DictIntegration;
import com.bifang.module.system.common.enums.CardTypeEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jwsoft.manager.common.enums.*;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheDetailVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheQueryVO;
import com.jwsoft.manager.common.vo.cache.EduOperationCacheVO;
import com.jwsoft.manager.common.vo.dygx.*;
import com.jwsoft.manager.common.vo.eduCompany.EduCompanyVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseHoldInterfaceVO;
import com.jwsoft.manager.common.vo.eduHouse.EduHouseVO;
import com.jwsoft.manager.common.vo.eduHouse.HouseInterfaceDetailVO;
import com.jwsoft.manager.common.vo.eduHouse.HouseInterfaceVO;
import com.jwsoft.manager.common.vo.eduHouseDetail.EduHouseDetailVO;
import com.jwsoft.manager.common.vo.eduHousehold.EduHouseholdVO;
import com.jwsoft.manager.common.vo.eduJhjyQuerySync.JhjyQueryVO;
import com.jwsoft.manager.common.vo.eduJhjySync.*;
import com.jwsoft.manager.common.vo.eduLivePlace.EduLivePlaceVO;
import com.jwsoft.manager.common.vo.eduNetsign.EduNetsignVO;
import com.jwsoft.manager.common.vo.eduSchool.EduSchoolVO;
import com.jwsoft.manager.common.vo.eduSchoolConfig.EduSchoolConfigVO;
import com.jwsoft.manager.common.vo.eduSocialSecurity.EduSocialSecurityVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.SaveStudentEnrollVO;
import com.jwsoft.manager.common.vo.eduStudentEnroll.StudentFormVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollBefore.BatchCreateVO;
import com.jwsoft.manager.common.vo.eduStudentEnrollPre.EduStudentEnrollPreKeyVO;
import com.jwsoft.manager.common.vo.eduSyncIrs.EduSyncIrsVO;
import com.jwsoft.manager.common.vo.individuation.*;
import com.jwsoft.manager.core.dao.model.*;
import com.jwsoft.manager.core.dao.service.*;
import com.jwsoft.manager.core.integration.EduSyncIrsIntegration;
import com.jwsoft.manager.core.integration.OperationCacheIntegration;
import com.jwsoft.manager.core.integration.common.DygxIntegration;
import com.jwsoft.manager.core.integration.individuation.IndividuationIntegration;
import com.jwsoft.manager.core.integration.individuation.helper.DyEnrollBeforeCreateHelper;
import com.jwsoft.manager.core.integration.individuation.helper.DyEnrollCalculateCreateHelper;
import com.jwsoft.manager.core.integration.individuation.helper.DyEnrollHelper;
import com.jwsoft.manager.core.util.EduEnrollClearCacheHelper;
import com.jwsoft.manager.core.util.EduHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 东阳个性化方法
 **/
@Service
@ApiService(funcCode = "F330783", title = "东阳个性化接口")
public class DyIndividuationIntegrationImpl implements IndividuationIntegration {
    @Autowired
    DyEnrollBeforeCreateHelper dyEnrollBeforeCreateHelper;
    @Autowired
    public DygxIntegration dygxIntegration;
    @Autowired
    public OperationCacheIntegration operationCacheIntegration;
    @Autowired
    public EduHouseholdService eduHouseholdService;
    @Autowired
    private EduSchoolService eduSchoolService;

    @Autowired
    public EduAddressService eduAddressService;

    @Autowired
    public EduHouseDetailService eduHouseDetailService;

    @Autowired
    public CommonIntegration commonIntegration;

    @Autowired
    public EduHouseService eduHouseService;

    @Autowired
    public DictIntegration dictIntegration;

    @Autowired
    public EduNetsignService eduNetsignService;

    @Autowired
    public EduSocialSecurityService eduSocialSecurityService;

    @Autowired
    public EduCompanyService eduCompanyService;

    @Autowired
    public EduLivePlaceService eduLivePlaceService;

    @Autowired
    private EduAuthSchoolService eduAuthSchoolService;
    @Autowired
    private EduStudentEnrollPreService eduStudentEnrollPreService;
    @Autowired
    private DyEnrollCalculateCreateHelper dyEnrollCalculateCreateHelper;
    @Autowired
    private DyEnrollHelper dyEnrollHelper;
    @Autowired
    private EduSocialSecurityDetailService eduSocialSecurityDetailService;
    @Autowired
    private EduEnrollClearCacheHelper eduEnrollClearCacheHelper;
    @Autowired
    private EduHelper eduHelper;
    @Autowired
    private EduHouseDetailNurseryService eduHouseDetailNurseryService;
    @Autowired
    private EduHouseNurseryService eduHouseNurseryService;
    @Autowired
    private EduSyncIrsIntegration eduSyncIrsIntegration;

    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    private final String areaCode = "330783";
    private final boolean cszFlag=false;//是否比对出生证信息

    @Override
    @OpApi(funcCode = "F3307830001", title = "东阳户籍接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduHouseholdVO> saveHouseHoldData(HouseHoldSaveVO vo) {
        List<EduHouseholdVO> eduHouseholdVOList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getIdcard())) {
            return null;
        }
        if(vo.getLocalFlag()==null){
            vo.setLocalFlag(false);
        }
        String bnxxFlag="1";
        String bnczFlag="1";
        if(StringUtils.isNotBlank(vo.getStudentEnrollPreId())){
            bnxxFlag="0";
            bnczFlag="0";
            EduStudentEnrollPre eduStudentEnrollPre=eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            if(eduStudentEnrollPre!=null){
                QueryWrapper<EduStudentEnrollPre> queryPreWrapper=new QueryWrapper<>();
                queryPreWrapper.lambda().select(EduStudentEnrollPre::getStudentEnrollPreId,EduStudentEnrollPre::getIdcard,EduStudentEnrollPre::getFatherIdcard,EduStudentEnrollPre::getMotherIdcard,EduStudentEnrollPre::getSchoolCategory)
                        .eq(EduStudentEnrollPre::getYear,eduHelper.thisYear())
                        .and( wrapper -> {
                            wrapper.eq(EduStudentEnrollPre::getIdcard, eduStudentEnrollPre.getIdcard())
                                    .or()
                                    .eq(EduStudentEnrollPre::getFatherIdcard, eduStudentEnrollPre.getFatherIdcard())
                                    .or()
                                    .eq(EduStudentEnrollPre::getMotherIdcard, eduStudentEnrollPre.getMotherIdcard());
                        });
                List<EduStudentEnrollPre> list=eduStudentEnrollPreService.list(queryPreWrapper);
                if (!CollectionUtils.isEmpty(list)&&list.size()>1){
                    for(EduStudentEnrollPre pre:list){
                        if(SchoolCategoryEnum.PRIMARY.getType().equals(pre.getSchoolCategory())){
                            bnxxFlag="1";
                        }
                        if(SchoolCategoryEnum.JUNIOR.getType().equals(pre.getSchoolCategory())){
                            bnczFlag="1";
                        }
                    }
                }else {
                    if (SchoolCategoryEnum.PRIMARY.getType().equals(eduStudentEnrollPre.getSchoolCategory())) {
                        bnxxFlag = "1";
                    }
                    if (SchoolCategoryEnum.JUNIOR.getType().equals(eduStudentEnrollPre.getSchoolCategory())) {
                        bnczFlag = "1";
                    }
                }
            }
        }
        vo.setBnczFlag(bnczFlag);
        vo.setBnxxFlag(bnxxFlag);
        try {
            int year = operationCacheIntegration.getPeriodYear().getYear();
            if (vo.getLocalFlag()) {
                List<DyHouseholdVO> dyHouseholdVOList=dygxIntegration.getDyHjInfo(vo.getIdcard(),vo.getReqIp());

                if (dyHouseholdVOList != null && dyHouseholdVOList.size() > 0) {
                    for(DyHouseholdVO item:dyHouseholdVOList) {
                        QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                        householdQueryWrapper
                                .lambda().select(EduHousehold::getHouseholdId,EduHousehold::getAddress)
                                .eq(EduHousehold::getYear, year)
                                .eq(EduHousehold::getIdcard, item.getGmsfhm().toUpperCase());
                        List<EduHousehold> oldList =
                                eduHouseholdService.list(householdQueryWrapper);
                        EduHousehold eduHousehold = new EduHousehold();
                        String oldAddress="";
                        if (!CollectionUtils.isEmpty(oldList)) {
                            eduHousehold.setHouseholdId(oldList.get(0).getHouseholdId());
                            oldAddress=oldList.get(0).getAddress();

                        }else{
                            eduHousehold.setHouseholdId(IdUtil.simpleUUID());
                        }
                        eduHousehold.setHhid(item.getHhid());
                        eduHousehold.setHh(item.getHh());
                        eduHousehold.setAccountType(item.getHb());
                        eduHousehold.setIdcard(item.getGmsfhm().toUpperCase());
                        eduHousehold.setFullName(item.getXm());
                        eduHousehold.setBeforeName(item.getCym());
                        eduHousehold.setSex(item.getXb());
                        eduHousehold.setBirthday(item.getCsrq());
                        eduHousehold.setNation(item.getMz());
                        eduHousehold.setNativePlace(item.getJgssxq());
                        eduHousehold.setBirthplace(item.getCsdssxq());
                        eduHousehold.setAddressCity(item.getHkszdxs());
                        eduHousehold.setAddressCountry(item.getHkszxzjd());
                        eduHousehold.setAddressVillage(item.getHkszdjcwh());
                        eduHousehold.setAddressVillageDetail(item.getHkszdjlx());
                        eduHousehold.setMlxz(item.getMlxz());
                        eduHousehold.setMlph(item.getMlph());
                        eduHousehold.setAddress(item.getHkAdreess());
                        eduHousehold.setHssqlbz(item.getHssqlbz());
                        eduHousehold.setHssqxqlws(item.getHssqxqlws());
                        eduHousehold.setHxzlbd(item.getHxzlbd());
                        eduHousehold.setHsqlbs(item.getHsqlbs());
                        eduHousehold.setHsqlbz(item.getHsqlbz());
                        eduHousehold.setQysj(item.getQysj());
                        eduHousehold.setJlbz(item.getJlbz());
                        eduHousehold.setRyzt(item.getRyzt());
                        eduHousehold.setRyid(item.getRyid());
                        eduHousehold.setYxqxqsrq(item.getYxqxqsrq());
                        eduHousehold.setYxqxjzrq(item.getYxqxjzrq());
                        eduHousehold.setPcs(item.getPcs());
                        eduHousehold.setQfjg(item.getQfjg());
                        eduHousehold.setRelation(item.getYhzgx());
                        eduHousehold.setXxqysj(item.getXxqysj());
                        eduHousehold.setAuthStatus(AuthStatusEnum.YES.getType());
                        eduHousehold.setStatus(BoolEnum.TRUE.getType());
                        eduHousehold.setYear(year+"");
                        if (StringUtils.isNotBlank(eduHousehold.getAddress())){
                            if(eduHousehold.getAddress().indexOf("东阳市")>=0){
                                eduHousehold.setAreaCode(areaCode);
                            }
                            if (StringUtils.isNotBlank(eduHousehold.getRegistrationAuthority())){
                                if(eduHousehold.getRegistrationAuthority().indexOf("东阳")>=0){
                                    eduHousehold.setAreaCode(areaCode);
                                }
                            }
                        }

                        String addressId =
                                eduAddressService.saveByAddress(eduHousehold.getAddress(),Integer.parseInt(eduHousehold.getYear()),vo.getBnxxFlag(),vo.getBnczFlag());
                        eduHousehold.setAddressId(addressId);
                        if (!eduHousehold.getAddress().equalsIgnoreCase(oldAddress)) {
                            //地址有变化才去更新
                            eduHouseholdService.saveOrUpdate(eduHousehold);
                        }
                        eduHouseholdVOList.add(Convert.convert(EduHouseholdVO.class,eduHousehold));
                    }
                }else{
                    QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                    householdQueryWrapper
                            .lambda()
                            .eq(EduHousehold::getIdcard, vo.getIdcard())
                            .eq(EduHousehold::getYear, year);
                    List<EduHousehold> oldList =
                            eduHouseholdService.list(householdQueryWrapper);
                    if (!CollectionUtils.isEmpty(oldList)) {
                        List<String> idList = oldList.stream()
                                .map(EduHousehold::getHouseholdId)
                                .collect(Collectors.toList());
                        eduHouseholdService.removeByIds(idList);
                    }
                }
            } else {
                CommonVO commonIrsAsyncVO = new CommonVO();
                commonIrsAsyncVO.setParamKey("irs_async");
                commonIrsAsyncVO.setAreaCode(areaCode);
                String irsAsync = commonIntegration.getValueByKeyAndArea(commonIrsAsyncVO);
                if (BoolEnum.TRUE.getType().equalsIgnoreCase(irsAsync) || "true".equalsIgnoreCase(irsAsync)) {
                    //异步调用，和省irs网络不通情况下，调用第三方分时段通平台 0-1 教育网通 1-2省网络通 交替
                    EduSyncIrsVO eduSyncIrsVO=new EduSyncIrsVO();
                    eduSyncIrsVO.setYear(year);
                    eduSyncIrsVO.setIrsCode("IRSGX0003");
                    eduSyncIrsVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
                    eduSyncIrsVO.setDataType(IrsSyncDataTypeEnum.idcard.getType());
                    eduSyncIrsVO.setSyncType(IrsSyncTypeEnum.hj.getType());
                    eduSyncIrsVO.setReqParams(JSON.toJSONString(vo));
                    eduSyncIrsVO.setDataId(vo.getIdcard());
                    eduSyncIrsIntegration.add(eduSyncIrsVO);
                    return eduHouseholdVOList;
                } else {
                    //同步调用，服务器网络和irs省网络联通条件下可直接调用
                    JSONArray jsonArray = dygxIntegration.getFamilyInfoIrs(vo.getIdcard(),vo.getReqIp());
                    if (jsonArray != null && jsonArray.size() > 0) {
                        jsonArray.forEach(
                                item -> {
                                    JSONObject personData = (JSONObject) item;
                                    EduHouseHoldInterfaceVO holdInterfaceVO =
                                            personData
                                                    .getJSONObject("ELC_LICENCE_STRUCT")
                                                    .getObject("DATA", EduHouseHoldInterfaceVO.class);
                                    String elcLicenceName = (String) personData.get("ELC_LICENCE_NAME");
                                    holdInterfaceVO.setElcLicenceName(elcLicenceName);
                                    QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                                    householdQueryWrapper
                                            .lambda().select(EduHousehold::getHouseholdId,EduHousehold::getAddress)
                                            .eq(EduHousehold::getYear, year)
                                            .eq(EduHousehold::getIdcard, holdInterfaceVO.getCZRKGMSFHM());
                                    List<EduHousehold> oldList =
                                            eduHouseholdService.list(householdQueryWrapper);
                                    EduHousehold eduHousehold = new EduHousehold();
                                    String oldAddress="";
                                    if (!CollectionUtils.isEmpty(oldList)) {
                                        eduHousehold.setHouseholdId(oldList.get(0).getHouseholdId());
                                        oldAddress=oldList.get(0).getAddress();
                                        eduHousehold.setQysj(oldList.get(0).getQysj());
                                        eduHousehold.setHsqlbz(oldList.get(0).getHsqlbz());
                                        eduHousehold.setHsqlbs(oldList.get(0).getHsqlbs());
                                    }else{
                                        eduHousehold.setHouseholdId(IdUtil.simpleUUID());
                                    }

                                    eduHousehold.setHhid(holdInterfaceVO.getCZRKHHID());
                                    eduHousehold.setHh(holdInterfaceVO.getCZRKHH());
                                    eduHousehold.setIdcard(holdInterfaceVO.getCZRKGMSFHM());
                                    eduHousehold.setFullName(holdInterfaceVO.getCZRKXM());
                                    eduHousehold.setAddress(holdInterfaceVO.getCZRKZZ());
                                    eduHousehold.setBirthday(holdInterfaceVO.getCZRKCSRQ());
                                    eduHousehold.setSex(holdInterfaceVO.getCZRKXB());
                                    eduHousehold.setCountry(holdInterfaceVO.getCZRKJGGJ());
                                    eduHousehold.setBirthplace(holdInterfaceVO.getCZRKCSDSSX());
                                    eduHousehold.setNativePlace(holdInterfaceVO.getCZRKJGSSX());
                                    eduHousehold.setHouseholdPlace(holdInterfaceVO.getCZRKZZ());
                                    eduHousehold.setAccountType(holdInterfaceVO.getElcLicenceName());
                                    eduHousehold.setRelation(holdInterfaceVO.getCZRKYHZGX());
                                    eduHousehold.setHouseholder(holdInterfaceVO.getCZRKHZXM());
                                    eduHousehold.setServiceSpaces(holdInterfaceVO.getCZRKFWCS());
                                    eduHousehold.setHsqlbz(holdInterfaceVO.getCZRKHSQLBS());
                                    eduHousehold.setHssqlbz(holdInterfaceVO.getCZRKHZQLSSX());
                                    eduHousehold.setHssqxqlws(holdInterfaceVO.getCZRKHDQLXZ());
                                    eduHousehold.setHxzlbd(holdInterfaceVO.getCZRKHZQLXZ());
                                    eduHousehold.setHsqlbs(holdInterfaceVO.getCZRKHZQLSSX());
                                    if (eduHousehold.getAddress().indexOf("东阳") >= 0) {
                                        //地址中包含东阳的就认为是东阳市地址
                                        eduHousehold.setAreaCode(areaCode);
                                    }
                                    if (StringUtils.isNotBlank(holdInterfaceVO.getCZRKHSQLBZ())) {
                                        try {
                                            if (holdInterfaceVO.getCZRKHSQLBZ().length() == 8) {
                                                eduHousehold.setRegistrationDate(DatePattern.PURE_DATE_FORMAT.parse(holdInterfaceVO.getCZRKHSQLBZ()));
                                            } else if (holdInterfaceVO.getCZRKHSQLBZ().length() == 10) {
                                                eduHousehold.setRegistrationDate(DatePattern.NORM_DATE_FORMAT.parse(holdInterfaceVO.getCZRKHSQLBZ()));
                                            }
                                        } catch (Exception e) {
                                            logger.error("户籍迁入时间格式转换异常");
                                        }

                                    }
                                    eduHousehold.setAuthStatus(AuthStatusEnum.YES.getType());
                                    eduHousehold.setStatus(BoolEnum.TRUE.getType());
                                    String yearString = Integer.toString(year);
                                    eduHousehold.setYear(yearString);
                                    String addressId =
                                            eduAddressService.saveByAddress(eduHousehold.getAddress(),Integer.parseInt(eduHousehold.getYear()),vo.getBnxxFlag(),vo.getBnczFlag());
                                    eduHousehold.setAddressId(addressId);
                                    if (!eduHousehold.getAddress().equalsIgnoreCase(oldAddress)) {
                                        eduHouseholdService.saveOrUpdate(eduHousehold);
                                    }
                                    eduHouseholdVOList.add(Convert.convert(EduHouseholdVO.class, eduHousehold));
                                });
                    } else {
                        QueryWrapper<EduHousehold> householdQueryWrapper = new QueryWrapper<>();
                        householdQueryWrapper
                                .lambda()
                                .eq(EduHousehold::getIdcard, vo.getIdcard())
                                .eq(EduHousehold::getYear, year);
                        List<EduHousehold> oldList =
                                eduHouseholdService.list(householdQueryWrapper);
                        if (!CollectionUtils.isEmpty(oldList)) {
                            List<String> idList = oldList.stream()
                                    .map(EduHousehold::getHouseholdId)
                                    .collect(Collectors.toList());
                            eduHouseholdService.removeByIds(idList);
                        }
                    }
                }
            }
        } catch(AppException e){
            throw e;
        } catch(Exception e){
            throw new AppException(e.getMessage());
        }

        return eduHouseholdVOList;
    }

    @Override
    @OpApi(funcCode = "F3307830002", title = "东阳房产接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduHouseVO> saveHouseInterfaceData(HouseInterfaceSaveVO vo) {
        String bnxxFlag="1";
        String bnczFlag="1";
        if(StringUtils.isNotBlank(vo.getStudentEnrollPreId())){
            bnxxFlag="0";
            bnczFlag="0";
            EduStudentEnrollPre eduStudentEnrollPre=eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
            if(eduStudentEnrollPre!=null){
                if(SchoolCategoryEnum.PRIMARY.getType().equals(eduStudentEnrollPre.getSchoolCategory())){
                    bnxxFlag="1";
                }
                if(SchoolCategoryEnum.JUNIOR.getType().equals(eduStudentEnrollPre.getSchoolCategory())){
                    bnczFlag="1";
                }
            }
        }
        vo.setBnczFlag(bnczFlag);
        vo.setBnxxFlag(bnxxFlag);
        List<EduHouseVO> eduHouseVOList = new ArrayList<>();
        try {
            int year = operationCacheIntegration.getPeriodYear().getYear();
            QueryWrapper<EduHouseDetail> oldDetailQueryWrapper = new QueryWrapper<>();
            oldDetailQueryWrapper
                    .lambda()
                    .in(EduHouseDetail::getIdcard, vo.getAllIdcardList())
                    .eq(EduHouseDetail::getYear, year)
                    .select(EduHouseDetail::getHouseId);
            List<EduHouseDetail> detailListOld = eduHouseDetailService.list(oldDetailQueryWrapper);
            List<String> houseIdList = new ArrayList<>();

            Map<String, List<EduHouseDetail>> oldGroupBy = new HashMap<>();
            if (!CollectionUtils.isEmpty(detailListOld)) {
                houseIdList = detailListOld.stream().map(EduHouseDetail::getHouseId).distinct().collect(Collectors.toList());
                QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                detailQueryWrapper.lambda().in(EduHouseDetail::getHouseId, houseIdList);
                List<EduHouseDetail> oldDetailList = eduHouseDetailService.list(detailQueryWrapper);
                if (!CollectionUtils.isEmpty(oldDetailList)) {
                    oldGroupBy = oldDetailList.stream().collect(Collectors.groupingBy(EduHouseDetail::getHouseId));
                }
            }
            //地址过滤
            CommonVO commonVO = new CommonVO();
            commonVO.setAreaCode(areaCode);
            commonVO.setParamKey("house_address_gl_key");
            String glHouseAddress = commonIntegration.getValueByKeyAndArea(commonVO);
            List<String> glAddressList = StringUtils.isNotBlank(glHouseAddress) ? Arrays.stream(glHouseAddress.split(",")).map(s -> s).collect(Collectors.toList()) : new ArrayList<>();
            CommonVO commonFcLxVO = new CommonVO();
            commonFcLxVO.setAreaCode(areaCode);
            commonFcLxVO.setParamKey("edu_house_type_filterate");
            String fclx = commonIntegration.getValueByKeyAndArea(commonFcLxVO);
            List<String> fclxList = StringUtils.isNotBlank(fclx) ? Arrays.stream(fclx.split(",")).map(s -> s).collect(Collectors.toList()) : new ArrayList<>();

            final Map<String, List<EduHouseDetail>> oldGroupByFinal = oldGroupBy;
            JSONArray houseArr = new JSONArray();
            if (StringUtils.isNotBlank(vo.getIdcard())) {
                JSONArray houseStArr = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard(),vo.getReqIp());
                if (houseStArr != null) {
                    houseArr.addAll(houseStArr);
                }
                if (vo.getIdcard().indexOf("X") > 0) {
                    JSONArray houseStArrX = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard().toLowerCase(),vo.getReqIp());
                    if (houseStArrX != null) {
                        houseArr.addAll(houseStArrX);
                    }
                }
            }

            if (StringUtils.isNotBlank(vo.getFatherIdcard())) {
                JSONArray houseFaArr = dygxIntegration.getPersonHouse(vo.getFatherName(), vo.getFatherIdcard(),vo.getReqIp());
                if (houseFaArr != null) {
                    houseArr.addAll(houseFaArr);
                }
                if (vo.getFatherIdcard().indexOf("X") > 0) {
                    JSONArray houseFaArrX = dygxIntegration.getPersonHouse(vo.getFatherName(), vo.getFatherIdcard().toLowerCase(),vo.getReqIp());
                    if (houseFaArrX != null) {
                        houseArr.addAll(houseFaArrX);
                    }
                }
            }
            if (StringUtils.isNotBlank(vo.getMotherIdcard())) {
                JSONArray houseMoArr = dygxIntegration.getPersonHouse(vo.getMotherName(), vo.getMotherIdcard(),vo.getReqIp());
                if (houseMoArr != null) {
                    houseArr.addAll(houseMoArr);
                }
                if (vo.getMotherIdcard().indexOf("X") > 0) {
                    JSONArray houseMoArrX = dygxIntegration.getPersonHouse(vo.getMotherName(), vo.getMotherIdcard().toLowerCase(),vo.getReqIp());
                    if (houseMoArrX != null) {
                        houseArr.addAll(houseMoArrX);
                    }
                }
            }
            List<String> oldHouseIdList = new ArrayList<>();
            if (houseArr.size() > 0) {
                int finalYear = year;
                List<Map<String, String>> hasList = new ArrayList<>();
                List<String> hasBdcdyhList = new ArrayList<>();
                for (Object item : houseArr) {
                    HouseInterfaceVO house = Convert.convert(HouseInterfaceVO.class, item);
                    String realProperty = house.getQlrxxList().stream()
                            .map(HouseInterfaceDetailVO::getBdcqzh)
                            .distinct()
                            .collect(Collectors.joining(","));

                    if (!ObjectUtils.isEmpty(house.getBdcdyh())) {
                        if (hasBdcdyhList.contains(house.getBdcdyh())) {
                            continue;
                        }
                        hasBdcdyhList.add(house.getBdcdyh());
                    } else {
                        Map<String, String> realMap = new HashMap<>();
                        realMap.put("realProperty", realProperty);
                        realMap.put("zl", house.getZl());
                        boolean continueFlg = false;
                        for (Map<String, String> map : hasList) {
                            if (map.get("realProperty").equals(realProperty) && map.get("zl").equals(house.getZl())) {
                                continueFlg = true;
                                break;
                            }
                        }
                        if (continueFlg) {
                            continue;
                        }
                        hasList.add(realMap);
                    }

                    QueryWrapper<EduHouse> houseQueryWrapper = new QueryWrapper<>();
                    List<String> qlrList = new ArrayList<>();
                    List<String> qlrAllList = new ArrayList<>();
                    String qlrName = "";
                    boolean idcardFlag = true;
                    List<String> qlrNameList = new ArrayList<>();
                    for (HouseInterfaceDetailVO detailVO : house.getQlrxxList()) {
                        if (StringUtils.isBlank(detailVO.getZjh())) {
                            idcardFlag = false;
                        } else {

                            if (IdcardUtil.isValidCard(detailVO.getZjh())) {
                                idcardFlag = false;
                                qlrAllList.add(detailVO.getZjh().toUpperCase());
                            } else {
                                if (detailVO.getZjh().length() == 15) {
                                    qlrList.add(IdcardUtil.convert15To18(detailVO.getZjh().toUpperCase()));
                                    qlrAllList.add(IdcardUtil.convert15To18(detailVO.getZjh().toUpperCase()));
                                } else {
                                    qlrList.add(detailVO.getZjh().toUpperCase());
                                    qlrAllList.add(detailVO.getZjh().toUpperCase());
                                }
                            }

                        }
                        qlrNameList.add(detailVO.getQlr().trim());
                        if (StringUtils.isBlank(qlrName)) {
                            qlrName = detailVO.getQlr() + "(" + detailVO.getZjh() + ")";
                        } else {
                            qlrName = qlrName + "," + detailVO.getQlr() + "(" + detailVO.getZjh() + ")";
                        }
                    }
                    EduHouse odlHouse = null;
                    if (ObjectUtils.isEmpty(house.getBdcdyh())) {
                        //不动单元号为空，使用不动产权号和证件类型查询
                        QueryWrapper<EduHouseDetail> houseDetailQueryWrapper =
                                new QueryWrapper<>();
                        houseDetailQueryWrapper
                                .lambda()
                                .eq(EduHouseDetail::getYear, finalYear)

                                .in(
                                        EduHouseDetail::getRealProperty,
                                        house.getQlrxxList().stream()
                                                .map(HouseInterfaceDetailVO::getBdcqzh)
                                                .collect(Collectors.toList()))
                                .in(
                                        EduHouseDetail::getIdcard,
                                        qlrAllList)
                                .select(EduHouseDetail::getHouseId);
                        List<EduHouseDetail> detailList = eduHouseDetailService.list(houseDetailQueryWrapper);
                        if (!CollectionUtils.isEmpty(detailList)) {
                            List<String> idList =
                                    detailList.stream()
                                            .map(EduHouseDetail::getHouseId)
                                            .distinct()
                                            .collect(Collectors.toList());
                            for (int i = 0; i < idList.size(); i++) {
                                EduHouse oldhouseById = eduHouseService.getById(idList.get(i));
                                if (oldhouseById != null && house.getZl().equals(oldhouseById.getAddress())) {
                                    odlHouse = oldhouseById;
                                }
                            }
                        }

                    } else {
                        houseQueryWrapper
                                .lambda()
                                .eq(EduHouse::getRealPropertyNum, house.getBdcdyh())
                                .eq(EduHouse::getRealProperty, realProperty)
                                .eq(EduHouse::getYear, finalYear);
                        odlHouse = eduHouseService.getOne(houseQueryWrapper);
                    }
                    String authStatus = null;
                    String status = null;
                    EduHouse eduHouse;
                    boolean newFlag = false;
                    boolean statusFlag = false;
                    if (!ObjectUtils.isEmpty(odlHouse)) {
                        if (oldHouseIdList.contains(odlHouse.getHouseId())) {
                            continue;
                        }
                        eduHouse = odlHouse;
                        oldHouseIdList.add(odlHouse.getHouseId());
                        statusFlag = true;
                        if(StringUtils.isNotBlank(odlHouse.getRemark())){
                            if(odlHouse.getRemark().indexOf("系统通过身份证判断")>=0){
                                statusFlag=false;
                            }
                            if(odlHouse.getRemark().indexOf("系统通过姓名判断")>=0){
                                statusFlag=false;
                            }
                            if(odlHouse.getRemark().indexOf("系统判断")>=0){
                                statusFlag=false;
                            }
                        }
                        if(statusFlag){
                            authStatus = odlHouse.getAuthStatus();//获取老数据的审核状态
                            status = odlHouse.getStatus();//获取老数据的有效状态
                        }

                        newFlag = false;
                    } else {
                        eduHouse = new EduHouse();
                        eduHouse.setHouseId(IdUtil.simpleUUID());
                        newFlag = true;
                    }
                    eduHouse.setAddress(house.getZl());
                    if (!ObjectUtils.isEmpty(house.getDjsj())) {
                        eduHouse.setRegisterDate(
                                DateUtil.parse(house.getDjsj(), "yyyy年MM月dd日"));
                    }
                    if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                        eduHouse.setRealProperty(realProperty);
                    }
                    eduHouse.setRealPropertyNum(house.getBdcdyh());
                    if (!ObjectUtils.isEmpty(house.getTdsyqssj())) {
                        eduHouse.setBegDate(
                                DateUtil.parse(house.getTdsyqssj(), "yyyy年MM月dd日"));
                    }
                    if (!ObjectUtils.isEmpty(house.getTdsyjssj())) {
                        eduHouse.setEndDate(
                                DateUtil.parse(house.getTdsyjssj(), "yyyy年MM月dd日"));
                    }
                    String yt = house.getYt().replace("/", "").trim();
                    eduHouse.setLandCategories(
                            saveDict("LANDCATEGORIES", yt, vo.getAccessToken()));
                    eduHouse.setLandCategoriesName(yt);
                    eduHouse.setHouseNature(
                            saveDict("HOUSENATURE", house.getFwxz(), vo.getAccessToken()));
                    eduHouse.setHouseNatureName(house.getFwxz());
                    eduHouse.setYear(finalYear);
                    eduHouse.setStatus("1");
                    eduHouse.setAuthStatus(AuthStatusEnum.NODO.getType());
                    ArrayList<EduHouseDetail> detailList = new ArrayList<>();
                    if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                        List<HouseInterfaceDetailVO> qlrxxList = house.getQlrxxList();
                        eduHouse.setQlrNum(qlrxxList.size());

                        eduHouse.setQlrName(qlrName);
                        if (qlrxxList.size() >= 3) {
                            //大于等于3个权利人的，设置为无效
                            eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                            eduHouse.setStatus(BoolEnum.FALSE.getType());
                            if (statusFlag) {
                                eduHouse.setRemark("系统判断权利人大于3个设置为无效");
                            }
                        } else if (qlrxxList.size() == 1) {
                            //1个权利人的直接通过
                            eduHouse.setAuthStatus(AuthStatusEnum.YES.getType());
                            eduHouse.setStatus(BoolEnum.TRUE.getType());
                        } else if (qlrxxList.size() == 2) {
                            //2个权利人的，如果是父母双方，则直接有效，不然就是无效
                            if (!CollectionUtils.isEmpty(qlrList)) {
                                if (idcardFlag) {

                                    if (vo.getAllIdcardList()
                                            .containsAll(qlrList)) {
                                        eduHouse.setAuthStatus(AuthStatusEnum.YES.getType());
                                        eduHouse.setStatus(BoolEnum.TRUE.getType());
                                    } else {
                                        eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                                        eduHouse.setStatus(BoolEnum.FALSE.getType());
                                        if (statusFlag) {
                                            eduHouse.setRemark("系统通过身份证判断权利人2个但不是父母双方设置为无效（" + JSON.toJSONString(vo.getAllIdcardList()) + "）和（" + JSON.toJSONString(qlrList) + "）");
                                        }
                                    }
                                } else {
                                    //用姓名来比对
                                    if (vo.getAllNameList().containsAll(qlrNameList)) {
                                        eduHouse.setAuthStatus(AuthStatusEnum.YES.getType());
                                        eduHouse.setStatus(BoolEnum.TRUE.getType());
                                    } else {
                                        eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                                        eduHouse.setStatus(BoolEnum.FALSE.getType());
                                        if (!statusFlag) {
                                            eduHouse.setRemark("系统通过姓名判断权利人2个但不是父母双方设置为无效（" + JSON.toJSONString(vo.getAllNameList()) + "）和（" + JSON.toJSONString(qlrNameList) + "）");
                                        }
                                    }
                                }

                            } else {
                                //遇到身份证返回为空情况，用姓名来比对
                                if (vo.getAllNameList().containsAll(qlrNameList)) {
                                    eduHouse.setAuthStatus(AuthStatusEnum.YES.getType());
                                    eduHouse.setStatus(BoolEnum.TRUE.getType());
                                } else {
                                    eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                                    eduHouse.setStatus(BoolEnum.FALSE.getType());
                                    if (!statusFlag) {
                                        eduHouse.setRemark("系统通过姓名判断权利人2个但不是父母双方设置为无效（" + JSON.toJSONString(vo.getAllNameList()) + "）和（" + JSON.toJSONString(qlrNameList) + "）");
                                    }
                                }
                            }
                        } else {
                            //没有权利人，直接无效
                            eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                            eduHouse.setStatus(BoolEnum.FALSE.getType());
                            if (statusFlag) {
                                eduHouse.setRemark("系统判断没有权利人设置为无效");
                            }
                        }
                        if (!ObjectUtils.isEmpty(house.getTdsyjssj())
                                && !ObjectUtils.isEmpty(house.getTdsyqssj())) {
                            int betweenYear =
                                    (int)
                                            DateUtil.betweenYear(
                                                    DateUtil.offsetDay(
                                                            DateUtil.parse(
                                                                    house.getTdsyqssj(),
                                                                    "yyyy年MM月dd日"),
                                                            -1),
                                                    DateUtil.parse(
                                                            house.getTdsyjssj(),
                                                            "yyyy年MM月dd日"),
                                                    false);
                            eduHouse.setYearLimit(betweenYear);
                        } else {
                            eduHouse.setYearLimit(100);
                        }
                        if (eduHouse.getYearLimit() > 20 && eduHouse.getYearLimit() <= 40) {
                            //小于70年产权的，全部设置不通过
                            eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                            eduHouse.setStatus(BoolEnum.FALSE.getType());
                            if (statusFlag) {
                                eduHouse.setRemark("系统判断产权20和40年之间设置为无效");
                            }
                        }
                        if (!ObjectUtils.isEmpty(odlHouse)) {
                            eduHouse.setRemark(odlHouse.getRemark());
                            eduHouse.setStreet(odlHouse.getStreet());
                        }

                        //不动产权号关键字过滤
                        if (!ObjectUtils.isEmpty(realProperty)
                                && (realProperty.contains("证明")
                                || realProperty.contains("预"))) {
                            //带证明和预字的设置为无效
                            eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                            eduHouse.setStatus(BoolEnum.FALSE.getType());
                            if (statusFlag) {
                                eduHouse.setRemark("系统判断房产证号上带有“证明”或“预”设置为无效");
                            }
                        }
                        //地址关键字过滤
                        if (!CollectionUtils.isEmpty(glAddressList)) {
                            for (String glStr : glAddressList) {
                                if (eduHouse.getAddress().contains(glStr)) {
                                    eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                                    eduHouse.setStatus(BoolEnum.FALSE.getType());
                                    if (statusFlag) {
                                        eduHouse.setRemark("系统判断地址上有不能使用的关键字(" + glStr + ")设置为无效");
                                    }

                                    break;
                                }
                            }
                        }
                        //房产类型过滤
                        if (!CollectionUtils.isEmpty(fclxList)) {
                            if (StringUtils.isNotBlank(eduHouse.getLandCategoriesName()) && fclxList.contains(eduHouse.getLandCategoriesName())) {
                                eduHouse.setAuthStatus(AuthStatusEnum.NO.getType());
                                eduHouse.setStatus(BoolEnum.FALSE.getType());
                                if (statusFlag) {
                                    eduHouse.setRemark("系统判断地址上有土地使用类型为(" + eduHouse.getLandCategoriesName() + ")设置为无效");
                                }
                            }

                        }

                        boolean detailFlag = true;
                        if (newFlag) {
                            detailFlag = true;
                            //新增
                        } else {
                            List<EduHouseDetail> details = oldGroupByFinal.get(eduHouse.getHouseId());
                            if (!CollectionUtils.isEmpty(details)) {
                                for (HouseInterfaceDetailVO qlrxx : house.getQlrxxList()) {
                                    EduHouseDetail detail = new EduHouseDetail();
                                    String qlrZjh = qlrxx.getZjh().toUpperCase();
                                    if (qlrZjh.length() == 15) {
                                        qlrZjh = IdcardUtil.convert15To18(qlrZjh);
                                    }
                                    detail.setHouseId(eduHouse.getHouseId());
                                    detail.setRealProperty(qlrxx.getBdcqzh());
                                    detail.setIdcard(qlrZjh);
                                    detail.setFullName(qlrxx.getQlr());
                                    detail.setCommonSituation(saveDict("COMMONSITUATION", qlrxx.getGyfs(), vo.getAccessToken()));
                                    detail.setCommonSituationName(qlrxx.getGyfs());
                                    detail.setYear(eduHouse.getYear());
                                    detail.setStatus("1");
                                    detail.setHouseDetailId(IdUtil.simpleUUID());
                                    for (EduHouseDetail houseDetail : details) {
                                        if (StringUtils.isBlank(qlrZjh)) {
                                            if (qlrxx.getQlr().equals(houseDetail.getFullName()) && qlrxx.getBdcqzh().equals(houseDetail.getRealProperty())) {
                                                detail.setHouseDetailId(houseDetail.getHouseDetailId());
                                                break;
                                            }
                                        } else {
                                            if (StringUtils.isNotBlank(houseDetail.getIdcard()) && qlrZjh.equals(houseDetail.getIdcard().toUpperCase())) {
                                                detail.setHouseDetailId(houseDetail.getHouseDetailId());
                                                break;
                                            }
                                        }
                                    }


                                    detailList.add(detail);
                                }
                                for (EduHouseDetail houseDetail : details) {
                                    boolean flag = true;
                                    for (HouseInterfaceDetailVO qlrxx : house.getQlrxxList()) {
                                        String qlrZjh = qlrxx.getZjh().toUpperCase();
                                        if (qlrZjh.length() == 15) {
                                            qlrZjh = IdcardUtil.convert15To18(qlrZjh);
                                        }
                                        if (StringUtils.isBlank(qlrZjh)) {
                                            if (qlrxx.getQlr().equals(houseDetail.getFullName()) && qlrxx.getBdcqzh().equals(houseDetail.getRealProperty())) {
                                                flag = false;
                                                break;
                                            }
                                        } else {
                                            if (StringUtils.isNotBlank(houseDetail.getIdcard()) && qlrZjh.equals(houseDetail.getIdcard().toUpperCase())) {
                                                flag = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (flag) {
                                        eduHouseDetailService.removeById(houseDetail.getHouseDetailId());
                                    }

                                }
                                detailFlag = false;
                            } else {
                                QueryWrapper<EduHouseDetail> delQuery = new QueryWrapper<>();
                                delQuery.lambda().eq(EduHouseDetail::getHouseId, eduHouse.getHouseId());
                                eduHouseDetailService.remove(delQuery);
                                detailFlag = true;

                            }
                        }
                        if (detailFlag) {
                            house.getQlrxxList().forEach(
                                    qlrxx -> {
                                        EduHouseDetail detail = new EduHouseDetail();
                                        detail.setHouseDetailId(IdUtil.simpleUUID());
                                        detail.setHouseId(eduHouse.getHouseId());
                                        detail.setRealProperty(qlrxx.getBdcqzh());
                                        String qlrZjh = qlrxx.getZjh().toUpperCase();
                                        if (qlrZjh.length() == 15) {
                                            qlrZjh = IdcardUtil.convert15To18(qlrZjh);
                                        }
                                        detail.setIdcard(qlrZjh);
                                        detail.setFullName(qlrxx.getQlr());
                                        detail.setCommonSituation(saveDict("COMMONSITUATION", qlrxx.getGyfs(), vo.getAccessToken()));
                                        detail.setCommonSituationName(qlrxx.getGyfs());
                                        detail.setYear(eduHouse.getYear());
                                        detail.setStatus(eduHouse.getStatus());
                                        detailList.add(detail);
                                    });
                        }

                    } else {
                        if (!newFlag) {
                            QueryWrapper<EduHouseDetail> delQuery = new QueryWrapper<>();
                            delQuery.lambda().eq(EduHouseDetail::getHouseId, eduHouse.getHouseId());
                            eduHouseDetailService.remove(delQuery);
                        }
                    }
                    if (!statusFlag && BoolEnum.TRUE.getType().equalsIgnoreCase(eduHouse.getStatus())) {
                        eduHouse.setRemark("");
                    }
                    if (vo.getOneFlag() == null || !vo.getOneFlag()) {
                        if (StringUtils.isNotBlank(status)) {
                            eduHouse.setStatus(status);
                        }
                        if (StringUtils.isNotBlank(authStatus)) {
                            eduHouse.setAuthStatus(authStatus);
                        }
                    } else {
                        //只有父母一方的，使用已有状态
                        if (StringUtils.isNotBlank(status)) {
                            eduHouse.setStatus(status);
                        }
                        if (StringUtils.isNotBlank(authStatus)) {
                            eduHouse.setAuthStatus(authStatus);
                        }

                    }

                    if (eduHouse.getStatus().equals(BoolEnum.TRUE.getType())) {
                        String addressId =
                                eduAddressService.saveByAddress(eduHouse.getAddress(),eduHouse.getYear(),vo.getBnxxFlag(),vo.getBnczFlag());
                        eduHouse.setAddressId(addressId);
                    }
                    eduHouse.setAreaCode(areaCode);
                    eduHouseService.saveOrUpdate(eduHouse);
                    if (!CollectionUtils.isEmpty(detailList)) {
                        eduHouseDetailService.saveOrUpdateBatch(detailList);
                    }
                    EduHouseVO houseVO = Convert.convert(EduHouseVO.class, eduHouse);

                    List<EduHouseDetailVO> detailVOList = Convert.toList(EduHouseDetailVO.class,detailList);
                    houseVO.setDetailList(detailVOList);
                    eduHouseVOList.add(houseVO);

                }
            }
            List<String> delHouseIdList = new ArrayList<>();
            if (CollectionUtils.isEmpty(oldHouseIdList)) {
                delHouseIdList.addAll(houseIdList);
            } else {
                for (String houseId : houseIdList) {
                    if (!oldHouseIdList.contains(houseId)) {
                        delHouseIdList.add(houseId);
                    }
                }
            }
            if (!CollectionUtils.isEmpty(delHouseIdList)) {
                QueryWrapper<EduHouseDetail> detailQueryWrapper = new QueryWrapper<>();
                detailQueryWrapper.lambda().in(EduHouseDetail::getHouseId, delHouseIdList);
                eduHouseDetailService.remove(detailQueryWrapper);
                eduHouseService.removeByIds(delHouseIdList);
            }
        } catch (AppException e) {
            logger.error("房产获取异常"+e.getMsg());
            throw e;
        } catch (Exception e) {
            logger.error("房产获取异常"+e.getMessage());
            throw new AppException(e.getMessage());
        }
        return eduHouseVOList;
    }


    @Override
    @OpApi(funcCode = "F3307830003", title = "东阳网签接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduNetsignVO> saveNetsignInterfaceData(NetsignSaveVO vo) {

        boolean replaceFlag = vo.getReplaceFlag();
        int year = operationCacheIntegration.getPeriodYear().getYear();
        List<WqVO> houseOnline = dygxIntegration.getHouseOnline(vo.getIdcard());
        List<EduNetsign> netsignList = Convert.toList(EduNetsign.class, houseOnline);

        QueryWrapper<EduNetsign> netsignQueryWrapper = new QueryWrapper<>();
        netsignQueryWrapper
                .lambda()
                .eq(EduNetsign::getIdcard, vo.getIdcard())
                .isNull(EduNetsign::getSchoolId)
                .eq(EduNetsign::getYear, year);
        List<EduNetsign> oldList = eduNetsignService.list(netsignQueryWrapper);
        if (oldList.size() > 0) {
            if (replaceFlag) {
                eduNetsignService.removeByIds(
                        oldList.stream()
                                .map(EduNetsign::getNetsignId)
                                .collect(Collectors.toList()));
            } else {
                return Convert.toList(EduNetsignVO.class, oldList);
            }
        }

        netsignList.forEach(
                item -> {
                    item.setNetsignId(IdUtil.simpleUUID());
                    item.setStatus(BoolEnum.TRUE.getType());
                    item.setYear(year);
                    item.setAreaCode(areaCode);
                    if (StringUtils.isBlank(item.getIdcard())) {
                        item.setIdcard(vo.getIdcard());
                    }
                    //网签暂不进地址池
                    /***
                     String addressId =
                     eduAddressService.saveByAddress(item.getDz());
                     item.setAddressId(addressId);
                     ***/
                });
        eduNetsignService.saveBatch(netsignList);
        return Convert.toList(EduNetsignVO.class, netsignList);
    }

    @Override
    @OpApi(funcCode = "F3307830025", title = "根据购房合同编号获取网签信息，金华接口", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduNetsignVO> saveNetsignJhInterfaceData(NetsignSaveVO vo) {
        List<WqVO> houseOnline =new ArrayList<>();
        if("1".equalsIgnoreCase(vo.getType())){
            houseOnline = dygxIntegration.getHouseOnlineJH1(vo.getIdcard(),vo.getHtbh(),vo.getHtbah(),vo.getAreaCode(),vo.getReqIp());
        }else{
            houseOnline = dygxIntegration.getHouseOnlineJH2(vo.getIdcard(),vo.getHtbh(),vo.getHtbah(),vo.getAreaCode(),vo.getReqIp());
        }

        if(CollectionUtils.isEmpty(houseOnline)){
            throw new AppException("系统未获取到购房合同信息");
        }
        boolean flag=true;
        for(WqVO wqVO:houseOnline){
            if(wqVO.getIdcard().equalsIgnoreCase(vo.getIdcard())){
                flag=false;
                break;
            }
        }
        if (flag){
            throw new AppException("请使用签订合同的人登录浙里办进行操作");
        }
        int year = operationCacheIntegration.getPeriodYear().getYear();
        QueryWrapper<EduNetsign> netsignQueryWrapper = new QueryWrapper<>();
        netsignQueryWrapper
                .lambda()
                .eq(EduNetsign::getIdcard, vo.getIdcard())
                .isNull(EduNetsign::getSchoolId)
                .eq(EduNetsign::getAreaCode,areaCode)
                .eq(EduNetsign::getYear, year);
        List<EduNetsign> oldList = eduNetsignService.list(netsignQueryWrapper);
        if(!CollectionUtils.isEmpty(oldList)){

            for(WqVO wqVO:houseOnline){
                boolean hasFlag=false;
                for(EduNetsign eduNetsign:oldList){
                    if(wqVO.getHtbabh().equalsIgnoreCase(eduNetsign.getHtbabh())){
                        hasFlag=true;
                        break;
                    }
                }
                if(!hasFlag){
                    EduNetsign eduNetsign=Convert.convert(EduNetsign.class,wqVO);
                    eduNetsign.setXqmc(wqVO.getHtbh());
                    eduNetsign.setStatus("1");
                    eduNetsign.setYear(year);
                    eduNetsign.setAreaCode(areaCode);
                    eduNetsignService.save(eduNetsign);
                }
            }
        }else{
            for(WqVO wqVO:houseOnline){

                EduNetsign eduNetsign=Convert.convert(EduNetsign.class,wqVO);
                eduNetsign.setStatus("1");
                eduNetsign.setAreaCode(areaCode);
                eduNetsign.setYear(year);
                eduNetsign.setXqmc(wqVO.getHtbh());
                eduNetsignService.save(eduNetsign);

            }
        }

        return Convert.toList(EduNetsignVO.class,houseOnline);
    }

    @Override
    @OpApi(funcCode = "F3307830004", title = "东阳参保接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduSocialSecurityVO> saveCbInterfaceData(CbSaveVO vo) {
        boolean replaceFlag = vo.getReplaceFlag();
        int year = operationCacheIntegration.getPeriodYear().getYear();
        List<CbVO> grcbDy = dygxIntegration.getGrcbDy(vo.getIdcard(),vo.getReqIp());
        List<EduSocialSecurity> socialSecurityList =
                Convert.toList(EduSocialSecurity.class, grcbDy);

        QueryWrapper<EduSocialSecurity> socialSecurityQueryWrapper = new QueryWrapper<>();
        socialSecurityQueryWrapper
                .lambda()
                .eq(EduSocialSecurity::getSourceType, SourceTypeEnum.gx.getType())
                .eq(EduSocialSecurity::getAac147, vo.getIdcard())
                .eq(EduSocialSecurity::getYear, year);
        List<EduSocialSecurity> oldList = eduSocialSecurityService.list(socialSecurityQueryWrapper);
        if (oldList.size() > 0) {
            if (replaceFlag) {
                eduSocialSecurityService.removeByIds(
                        oldList.stream()
                                .map(EduSocialSecurity::getSocialSecurityId)
                                .collect(Collectors.toList()));
            } else {
                return Convert.toList(EduSocialSecurityVO.class, oldList);
            }
        }

        for (EduSocialSecurity item : socialSecurityList) {
            item.setSocialSecurityId(IdUtil.simpleUUID());
            item.setYear(year);
            item.setSourceType(SourceTypeEnum.gx.getType());
            item.setTotalFlag(BoolEnum.FALSE.getType());
            item.setTotalErrorCnt(0);
            if (StringUtils.isBlank(item.getAab301())){
                item.setAab301(areaCode);
            }
            if ("110".equalsIgnoreCase(item.getAae140()) || "120".equalsIgnoreCase(item.getAae140())) {
                //删除之前缴费明细数据
                QueryWrapper<EduSocialSecurityDetail> queryWrapper = new QueryWrapper<>();
                queryWrapper.lambda().eq(EduSocialSecurityDetail::getAac147, vo.getIdcard())
                        .eq(EduSocialSecurityDetail::getYear, year);
                eduSocialSecurityDetailService.remove(queryWrapper);
                if ("1".equalsIgnoreCase(item.getAac008()) && "1".equalsIgnoreCase(item.getAac031())) {
                    try {
                        List<EduSocialSecurityDetail> detailList = dygxIntegration.getCbDetail(vo.getIdcard(),vo.getReqIp());
                        if (!CollectionUtils.isEmpty(detailList)) {
                            detailList = detailList.stream().sorted(Comparator.comparing(EduSocialSecurityDetail::getAae003, Comparator.reverseOrder())).collect(Collectors.toList());
                            Date curTime = DateUtil.offsetMonth(new Date(), -2);
                            int count = 0;
                            int i = 0;
                            Map<String,String> map=new HashMap<>();
                            List<EduSocialSecurityDetail> saveDetailList=new ArrayList<>();
                            for (EduSocialSecurityDetail eduSocialSecurityDetail : detailList) {
                                eduSocialSecurityDetail.setSocialSecurityId(item.getSocialSecurityId());
                                eduSocialSecurityDetail.setYear(year);
                                if(!map.containsKey(eduSocialSecurityDetail.getAaz223())){
                                    map.put(eduSocialSecurityDetail.getAaz223(),eduSocialSecurityDetail.getAaz223());
                                    saveDetailList.add(eduSocialSecurityDetail);
                                }
                            }
                            for (EduSocialSecurityDetail eduSocialSecurityDetail : saveDetailList) {
                                int thisMonth = Integer.parseInt(DateUtil.format(curTime, "YYYYMM"));
                                if (count <= 5 ) {
                                    if (StringUtils.isNotBlank(eduSocialSecurityDetail.getAae003())) {
                                        if( thisMonth == Integer.parseInt(eduSocialSecurityDetail.getAae003())) {
                                            if (i == 0) {
                                                count = count + 1;
                                            } else {
                                                if ("1".equalsIgnoreCase(eduSocialSecurityDetail.getAae078())) {
                                                    count = count + 1;
                                                } else {
                                                    break;
                                                }
                                            }
                                        }else if(thisMonth < Integer.parseInt(eduSocialSecurityDetail.getAae003())){
                                            continue;
                                        }else{
                                            break;
                                        }
                                    } else {
                                        break;
                                    }

                                } else {
                                    break;
                                }
                                i = i + 1;
                                curTime = DateUtil.offsetMonth(curTime, -1);

                            }
                            if (count >= 5) {
                                item.setContinuityFlag(BoolEnum.TRUE.getType());
                            } else {
                                item.setContinuityFlag(BoolEnum.FALSE.getType());
                            }
                            eduSocialSecurityDetailService.saveBatch(saveDetailList);
                        } else {
                            item.setContinuityFlag(BoolEnum.FALSE.getType());
                            item.setContinuityMsg("获取成功，大数据返回无缴费明细");
                        }


                    } catch (AppException e) {
                        logger.error("获取社保缴费明细信息异常"+e.getMsg());
                        item.setContinuityFlag(BoolEnum.FALSE.getType());
                        String msg=e.getMsg();
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,260);
                        }
                        item.setContinuityMsg(msg);
                    } catch (Exception e) {
                        logger.error("获取社保缴费明细信息异常"+e.getMessage());
                        item.setContinuityFlag(BoolEnum.FALSE.getType());
                        String msg=e.getMessage();
                        if(StringUtils.isNotBlank(msg)&&msg.length()>300){
                            msg=msg.substring(0,260);
                        }
                        item.setContinuityMsg(msg);
                    }
                }
            }

        }

        eduSocialSecurityService.saveOrUpdateBatch(socialSecurityList);
        return Convert.toList(EduSocialSecurityVO.class, socialSecurityList);
    }

    @Override
    @OpApi(funcCode = "F3307830024", title = "东阳参保缴费明细接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void saveCbJfInterfaceData(EduSocialSecurity item,String ip) {

    }

    @Override
    @OpApi(funcCode = "F3307830005", title = "东阳企业接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduCompanyVO> saveQyInterfaceData(QySaveVO vo) {
        if (vo.getLocalFlag() == null) {
            vo.setLocalFlag(false);
        }
        int year = operationCacheIntegration.getPeriodYear().getYear();
        if (vo.getLocalFlag()) {
            String tyxydm = vo.getTyxydm();
            if (StringUtils.isNotBlank(vo.getIdcard())) {
                List<String> aae140List = new ArrayList<>();
                aae140List.add("110");
                aae140List.add("120");
                aae140List.add("170");
                QueryWrapper<EduSocialSecurity> socialSecurityQueryWrapper = new QueryWrapper<>();
                socialSecurityQueryWrapper
                        .lambda()
                        .eq(EduSocialSecurity::getAac147, vo.getIdcard())
                        .eq(EduSocialSecurity::getAac008, BoolEnum.TRUE.getType())
                        .eq(EduSocialSecurity::getAac031, BoolEnum.TRUE.getType())
                        .in(EduSocialSecurity::getAae140, aae140List)
                        .eq(EduSocialSecurity::getAab301, "330783")
                        .eq(EduSocialSecurity::getYear, year);
                List<EduSocialSecurity> list =
                        eduSocialSecurityService.list(socialSecurityQueryWrapper);
                if (!ObjectUtils.isEmpty(list)) {
                    EduSocialSecurity eduSocialSecurity = list.get(0);
                    tyxydm = eduSocialSecurity.getBab010();

                }
            }
            return getQyInterface(tyxydm, year, true);
        } else {
            List<EduCompanyVO> companyVOList = new ArrayList<>();
            CommonVO commonIrsAsyncVO = new CommonVO();
            commonIrsAsyncVO.setParamKey("irs_async");
            commonIrsAsyncVO.setAreaCode(areaCode);
            String irsAsync = commonIntegration.getValueByKeyAndArea(commonIrsAsyncVO);
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(irsAsync) || "true".equalsIgnoreCase(irsAsync)) {
                //异步调用，和省irs网络不通情况下，调用第三方分时段通平台 0-1 教育网通 1-2省网络通 交替
                EduSyncIrsVO eduSyncIrsVO = new EduSyncIrsVO();
                eduSyncIrsVO.setYear(year);
                eduSyncIrsVO.setIrsCode("IRSGX0004");
                eduSyncIrsVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
                eduSyncIrsVO.setDataType(IrsSyncDataTypeEnum.idcard.getType());
                eduSyncIrsVO.setSyncType(IrsSyncTypeEnum.qy.getType());
                eduSyncIrsVO.setReqParams(JSON.toJSONString(vo));
                eduSyncIrsVO.setDataId(vo.getIdcard());
                eduSyncIrsIntegration.add(eduSyncIrsVO);
                return new ArrayList<>();
            } else {
                //同步调用，服务器网络和irs省网络联通条件下可直接调用
                JSONArray jsonArray = dygxIntegration.getFrQyIrs(vo.getIdcard());
                QueryWrapper<EduCompany> oldQuery = new QueryWrapper<>();
                oldQuery.lambda().eq(EduCompany::getYear, year)
                        .eq(EduCompany::getFrZjhm, vo.getIdcard());
                List<EduCompany> oldList = eduCompanyService.list(oldQuery);
                if (jsonArray != null && jsonArray.size() > 0) {
                    jsonArray.forEach(
                            item -> {
                                JSONObject data = (JSONObject) item;
                                EduCompany eduCompany = new EduCompany();
                                eduCompany.setTyxydm(data.getString("uniscid"));
                                eduCompany.setFrdwmc(data.getString("entname"));
                                eduCompany.setFrmc(data.getString("name"));
                                eduCompany.setFrZjhm(vo.getIdcard());
                                eduCompany.setAreaCode(data.getString("yiedistrict"));
                                eduCompany.setHzrq(data.getString("apprdate"));
                                eduCompany.setShzzlx(data.getString("compform"));
                                eduCompany.setJyqsrq(data.getString("opfrom"));
                                eduCompany.setJyjzrq(data.getString("opto"));
                                eduCompany.setDjrq(data.getString("estdate"));
                                eduCompany.setZczb(data.getString("regcap"));
                                eduCompany.setBmBz(data.getString("regcapcur"));
                                eduCompany.setDjjg(data.getString("regorg"));
                                eduCompany.setCxzt(data.getString("regstate"));
                                if (StringUtils.isNotBlank(eduCompany.getTyxydm())) {
                                    if (!CollectionUtils.isEmpty(oldList)) {
                                        for (EduCompany old : oldList) {
                                            if (old.getTyxydm().equalsIgnoreCase(eduCompany.getTyxydm())) {
                                                eduCompany.setCompanyId(old.getCompanyId());
                                                break;
                                            }
                                        }
                                    }
                                    eduCompanyService.saveOrUpdate(eduCompany);
                                    EduCompanyVO eduCompanyVO = Convert.convert(EduCompanyVO.class, eduCompany);
                                    companyVOList.add(eduCompanyVO);
                                }

                            });
                    if (!CollectionUtils.isEmpty(oldList)) {
                        for (EduCompany old : oldList) {
                            boolean flag = false;
                            for (EduCompanyVO newVO : companyVOList) {
                                if (old.getCompanyId().equalsIgnoreCase(newVO.getCompanyId())) {
                                    flag = true;
                                    break;
                                }
                            }
                            if (!flag) {
                                eduCompanyService.removeById(old.getCompanyId());
                            }
                        }
                    }
                } else {

                    if (!CollectionUtils.isEmpty(oldList)) {
                        List<String> idList = oldList.stream()
                                .map(EduCompany::getCompanyId)
                                .collect(Collectors.toList());
                        eduHouseholdService.removeByIds(idList);
                    }
                }
                return companyVOList;
            }
        }
    }

    @Override
    @OpApi(funcCode = "F3307830006", title = "东阳居住证接口信息获取并保存", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduLivePlaceVO> saveJzzInterfaceData(JzzSaveVO vo) {
        boolean replaceFlag = vo.getReplaceFlag();
        int year = operationCacheIntegration.getPeriodYear().getYear();
        if (vo.getLocalFlag() == null) {
            vo.setLocalFlag(true);
        }
        QueryWrapper<EduLivePlace> livePlaceQueryWrapper = new QueryWrapper<>();
        livePlaceQueryWrapper
                .lambda()
                .eq(EduLivePlace::getSourceType, SourceTypeEnum.gx.getType())
                .eq(EduLivePlace::getSfzh, vo.getIdcard())
                .eq(EduLivePlace::getYear, year);


        List<EduLivePlace> oldList = eduLivePlaceService.list(livePlaceQueryWrapper);
        if (!CollectionUtils.isEmpty(oldList)) {
            if (!replaceFlag) {
                return Convert.toList(EduLivePlaceVO.class, oldList);
            }
        }
        List<DyJzzVO> jzzVOList = new ArrayList<>();
        if (vo.getLocalFlag()) {
            jzzVOList = dygxIntegration.getDyJzz(vo.getIdcard(),vo.getReqIp());
        } else {
            CommonVO commonIrsAsyncVO = new CommonVO();
            commonIrsAsyncVO.setParamKey("irs_async");
            commonIrsAsyncVO.setAreaCode(areaCode);
            String irsAsync = commonIntegration.getValueByKeyAndArea(commonIrsAsyncVO);
            if (BoolEnum.TRUE.getType().equalsIgnoreCase(irsAsync) || "true".equalsIgnoreCase(irsAsync)) {
                //异步调用，和省irs网络不通情况下，调用第三方分时段通平台 0-1 教育网通 1-2省网络通 交替
                EduSyncIrsVO eduSyncIrsVO = new EduSyncIrsVO();
                eduSyncIrsVO.setYear(year);
                eduSyncIrsVO.setIrsCode("IRSGX0005");
                eduSyncIrsVO.setStudentEnrollPreId(vo.getStudentEnrollPreId());
                eduSyncIrsVO.setDataType(IrsSyncDataTypeEnum.idcard.getType());
                eduSyncIrsVO.setSyncType(IrsSyncTypeEnum.jzz.getType());
                eduSyncIrsVO.setReqParams(JSON.toJSONString(vo));
                eduSyncIrsVO.setDataId(vo.getIdcard());
                eduSyncIrsIntegration.add(eduSyncIrsVO);
                return new ArrayList<>();
            } else {
                //同步调用，服务器网络和irs省网络联通条件下可直接调用
                JSONArray jsonArray = dygxIntegration.getJzzIrs(vo.getIdcard(), vo.getName(),vo.getReqIp());
                if (jsonArray != null && jsonArray.size() > 0) {
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JSONObject dataAll = jsonArray.getJSONObject(i);
                        if (dataAll.get("ELC_LICENCE_STRUCT")==null){
                            continue;
                        }
                        JSONObject dataS = dataAll.getJSONObject("ELC_LICENCE_STRUCT");
                        if (dataS.get("DATA")==null){
                            continue;
                        }
                        JSONObject data=dataS.getJSONObject("DATA");
                        DyJzzVO jzzVO = new DyJzzVO();
                        jzzVO.setSfzh(data.getString("SFZH"));
                        jzzVO.setXm(data.getString("XM"));
                        jzzVO.setXb(data.getString("XB"));
                        jzzVO.setZjnbbh(data.getString("ZJNBBH"));
                        jzzVO.setZjzt(data.getString("ZJZT"));
                        jzzVO.setMz(data.getString("MZ"));
                        jzzVO.setJzdz(data.getString("JZDZ"));
                        jzzVO.setHjdz(data.getString("HJDZ"));
                        jzzVO.setHksxdm(data.getString("HKSXDM"));
                        jzzVO.setHksx(data.getString("HKSX"));
                        jzzVO.setQzrq(data.getString("FZRQ"));
                        jzzVO.setFzdgajg(data.getString("FZDGAJG"));
                        if(data.get("FZDGAJGDM")!=null&&StringUtils.isNotBlank(data.getString("FZDGAJGDM"))){
                            jzzVO.setAreaCode(data.getString("FZDGAJGDM"));
                        }
                        if (StringUtils.isNotBlank(jzzVO.getFzdgajg())&&jzzVO.getFzdgajg().indexOf("东阳市") >= 0) {
                            jzzVO.setXzqhdm("330783");
                            jzzVO.setAreaCode(jzzVO.getXzqhdm());
                        }
                        if("正常".equalsIgnoreCase(jzzVO.getZjzt())){
                            jzzVO.setZjztdm("2");
                        }
                        jzzVO.setAreaCode(jzzVO.getXzqhdm());
                        jzzVOList.add(jzzVO);
                    }
                }
            }
        }

        if (CollectionUtils.isEmpty(jzzVOList)) {
            if (!CollectionUtils.isEmpty(oldList) && replaceFlag) {
                eduLivePlaceService.removeByIds(
                        oldList.stream()
                                .map(EduLivePlace::getLivePlaceId)
                                .collect(Collectors.toList()));
            }
            return new ArrayList<>();
        }
        List<EduLivePlace> livePlaceList = Convert.toList(EduLivePlace.class, jzzVOList);
        livePlaceList.forEach(
                item -> {
                    item.setLivePlaceId(IdUtil.simpleUUID());
                    if (!CollectionUtils.isEmpty(oldList)) {
                        for (EduLivePlace eduLivePlace : oldList) {
                            if (StringUtils.isNotBlank(eduLivePlace.getZjnbbh())&&eduLivePlace.getZjnbbh().equalsIgnoreCase(item.getZjnbbh())) {
                                item.setLivePlaceId(eduLivePlace.getLivePlaceId());
                                break;
                            }
                        }
                    }
                    item.setYear(year);
                    item.setSourceType(SourceTypeEnum.gx.getType());
                    item.setAreaCode(item.getFzdgajgdm());
                    if (StringUtils.isBlank(item.getAreaCode())){
                        item.setAreaCode(item.getXzqhdm());
                    }
                });
        if (!CollectionUtils.isEmpty(oldList)) {
            for (EduLivePlace old : oldList) {
                boolean flag = true;
                for (EduLivePlace newPlace : livePlaceList) {
                    if (StringUtils.isNotBlank(newPlace.getZjnbbh())&&newPlace.getZjnbbh().equalsIgnoreCase(old.getZjnbbh())) {
                        flag = false;
                    }
                }
                if (flag) {
                    eduLivePlaceService.removeById(old.getLivePlaceId());
                }
            }
        }
        eduLivePlaceService.saveOrUpdateBatch(livePlaceList);
        return Convert.toList(EduLivePlaceVO.class, livePlaceList);
    }

    @Override
    @OpApi(funcCode = "F3307830007", title = "东阳单个可报名数据生成", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    @Transactional
    public int createEnrollBefore(EduStudentEnrollPre eduStudentEnrollPre) {
        int count=createBefore(eduStudentEnrollPre);
        eduEnrollClearCacheHelper.clearCachePreBefore(eduStudentEnrollPre.getStudentEnrollPreId());
        return count;
    }

    @Override
    @OpApi(funcCode = "F3307830013", title = "东阳批量生成预测数据", funcType = FuncTypeEnum.edit, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void createCalculateBatch(BatchCreateVO vo) {
        createCalculateBatchPageInfo(vo);
    }


    @Override
    @OpApi(funcCode = "F3307830008", title = "东阳我的报名查询", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void getMyEnrollInfo(List<StudentFormVO> myEnrollInfo) {
        int year = eduHelper.thisYear();
        EduOperationCacheQueryVO queryVO = new EduOperationCacheQueryVO();
        queryVO.setAreaCode(areaCode);
        queryVO.setClassify("2");
        queryVO.setYear(year);
        queryVO.setKeyTime(queryVO.getClassify()+":"+queryVO.getAreaCode()+":"+ DateUtil.format(new Date(),"yyyyMMdd"));
        EduOperationCacheVO eduOperationCacheVO = operationCacheIntegration.getEduOperation(queryVO);

        Map<String, EduOperationCacheDetailVO> operation = eduOperationCacheVO.getOperation();
        EduOperationCacheDetailVO bmOperation = operation.get("YW002");//报名时间
        EduOperationCacheDetailVO bbOperation = operation.get("YW022");//补报时间
        EduOperationCacheDetailVO qbOperation = operation.get("YW010");//抢报时间
        //判断是否报名业务期
        boolean bmFlag = bmOperation == null ? false : bmOperation.isFlag();
        //判断是否补报业务期
        boolean bbFlag = bmFlag || bbOperation == null ? false : bbOperation.isFlag();
        //判断是否空额抢报业务期
        boolean qbFlag = bmFlag || qbOperation == null ? false : qbOperation.isFlag();

        for (StudentFormVO studentFormVO : myEnrollInfo) {
            studentFormVO.setCanBack(false);
            if (year - studentFormVO.getYear() == 0 ){
                //本年的，显示招生咨询电话
                EduSchoolVO eduSchoolVO=eduSchoolService.getDetail(studentFormVO.getSchoolId());
                studentFormVO.setPhone(eduSchoolVO.getZsPhone());
                studentFormVO.setContacts(eduSchoolVO.getZsContacts());
                if (AuthStatusEnum.NODO.getType().equals(studentFormVO.getAuthStatus())) {
                    if ("1".equals(studentFormVO.getSchoolCategory())) {
                        //幼儿园根据招生计划里面的时间判断是否可撤销
                        if (!CollectionUtils.isEmpty(eduSchoolVO.getConfigList())) {
                            long curTime = DateUtil.currentSeconds();
                            for (EduSchoolConfigVO configVO : eduSchoolVO.getConfigList()) {
                                if (configVO.getEndTime() != null && StringUtils.isNotBlank(configVO.getConfigType())) {
                                    if (configVO.getConfigType().equals(studentFormVO.getConfigType())) {
                                        long endT = configVO.getEndTime().getTime() / 1000;
                                        if (curTime - endT <= 0) {
                                            studentFormVO.setCanBack(true);
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        //义务段招生参数里面的时间判断是否可撤销
                        if ("1".equals(studentFormVO.getBbFlag())||"1".equals(studentFormVO.getSpareRegisterFlag())){
                            if ("1".equals(studentFormVO.getBbFlag())){
                                if (bbFlag){
                                    studentFormVO.setCanBack(true);
                                }
                            }
                            if("1".equals(studentFormVO.getSpareRegisterFlag())){
                                if (qbFlag){
                                    studentFormVO.setCanBack(true);
                                }
                            }
                        }else{
                            if (SchoolNatureEnum.gb.getType().equals(studentFormVO.getSchoolNature())){
                                //第一次报名只有公办学校才能撤销
                                if (bmFlag){
                                    studentFormVO.setCanBack(true);
                                }
                            }
                        }
                    }
                }
            }
            if ("1".equals(studentFormVO.getSchoolCategory())) {
                if (AuthStatusEnum.NODO.getType().equals(studentFormVO.getAuthStatus())) {
                    studentFormVO.setEnrollStatus("0");
                    studentFormVO.setEnrollStatusName("待审核");

                } else if (AuthStatusEnum.YES.getType().equals(studentFormVO.getAuthStatus())) {
                    if (StringUtils.isBlank(studentFormVO.getAdmitFlag())) {
                        studentFormVO.setEnrollStatus("1");
                        studentFormVO.setEnrollStatusName("资料审核通过");
                    } else {
                        if (BoolEnum.TRUE.getType().equals(studentFormVO.getAdmitFlag())) {
                            studentFormVO.setEnrollStatus("2");
                            studentFormVO.setEnrollStatusName("已录取");
                        } else {
                            studentFormVO.setEnrollStatus("3");
                            studentFormVO.setEnrollStatusName("不予录取");
                        }
                    }
                } else if (AuthStatusEnum.NO.getType().equals(studentFormVO.getAuthStatus())) {
                    studentFormVO.setEnrollStatus("3");
                    studentFormVO.setEnrollStatusName("不予录取");
                }
            } else {
                if ("0".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("待审核");
                } else if ("1".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("资料审核通过");
                } else if ("2".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("已录取");
                } else if ("3".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("不予录取");
                } else if ("4".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("无效");
                } else if ("5".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("未派中");
                } else if ("6".equals(studentFormVO.getEnrollStatus())) {
                    studentFormVO.setEnrollStatusName("主动退出");
                }
            }

        }

    }

    @Override
    @OpApi(funcCode = "F3307830009", title = "东阳家庭成员比对接口", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public String getFamInfoComparison(EduStudentEnrollPreKeyVO vo) {
        EduStudentEnrollPre eduStuEnrollPre = eduStudentEnrollPreService.getById(vo.getStudentEnrollPreId());
        if (eduStuEnrollPre == null) {
            throw new AppException("未找到预采集数据");
        }
        String infoComparison = "4";
        //判断户籍和房产是获取
        if(!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStuEnrollPre.getHouseholdSyncFlag())||!BoolEnum.TRUE.getType().equalsIgnoreCase(eduStuEnrollPre.getHouseSyncFlag())){
            return "0";
        }
        infoComparison = this.getStuFamInfoComparison(eduStuEnrollPre);
        String msg = "";
        switch (infoComparison) {
            case "1":
                msg = "比对通过";
                break;
            case "2":
                msg = "父亲通过母亲不通过";
                break;
            case "3":
                msg = "母亲通过父亲不通过";
                break;
            case "4":
                msg = "不通过";
                break;
            case "9":
                msg = "没有在东阳户籍和房产，不比对";
        }
        UpdateWrapper<EduStudentEnrollPre> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(EduStudentEnrollPre::getStudentEnrollPreId, eduStuEnrollPre.getStudentEnrollPreId())
                .set(EduStudentEnrollPre::getFamilyFlag, infoComparison)
                .set(EduStudentEnrollPre::getFamilyRemark, msg);
        eduStudentEnrollPreService.update(updateWrapper);

        return infoComparison;
    }

    @Override
    @OpApi(funcCode = "F3307830010", title = "东阳批量生成预报名数据", funcType = FuncTypeEnum.insert, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void createBatch(BatchCreateVO vo) {
        createBatchPageInfo(vo);
    }

    private String getStuFamInfoComparison(EduStudentEnrollPre eduStuEnrollPre) {
        CszmQueryVO cszmQueryVO = new CszmQueryVO();

        Boolean haveFatherIDFlag = StringUtils.isNotBlank(eduStuEnrollPre.getFatherIdcard());
        Boolean haveMotherIDFlag = StringUtils.isNotBlank(eduStuEnrollPre.getMotherIdcard());
        Boolean haveStuNameFlag = StringUtils.isNotBlank(eduStuEnrollPre.getFullName());

        if (haveStuNameFlag) {
            cszmQueryVO.setXm(eduStuEnrollPre.getFullName().trim());
        } else {
            throw new AppException("学生姓名不能为空！");
        }
        if (!haveFatherIDFlag && !haveMotherIDFlag) {
            throw new AppException("父亲或母亲身份证至少存在一个，不可全为空！");
        }
        //比对孩子是否在父母中一个的户口本下
        Boolean faFlag = false;
        Boolean moFlag = false;
        String infoComparison="4";
        LambdaQueryWrapper<EduHousehold> householdLambdaQueryWrapper = new LambdaQueryWrapper<>();
        householdLambdaQueryWrapper.select(EduHousehold::getHh).eq(EduHousehold::getYear, eduStuEnrollPre.getYear())
                .eq(EduHousehold::getIdcard, eduStuEnrollPre.getIdcard())
                .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType());
        EduHousehold child = eduHouseholdService.getOne(householdLambdaQueryWrapper, false);
        //判断房产是否存在
        List<String> allIdcardList=new ArrayList<>();
        allIdcardList.add(eduStuEnrollPre.getIdcard());
        if(StringUtils.isNotBlank(eduStuEnrollPre.getMotherIdcard())){
            allIdcardList.add(eduStuEnrollPre.getMotherIdcard());
        }
        if(StringUtils.isNotBlank(eduStuEnrollPre.getFatherIdcard())){
            allIdcardList.add(eduStuEnrollPre.getFatherIdcard());
        }
        QueryWrapper<EduHouseDetail> oldDetailQueryWrapper = new QueryWrapper<>();
        oldDetailQueryWrapper
                .lambda()
                .select(EduHouseDetail::getHouseId,EduHouseDetail::getIdcard,EduHouseDetail::getFullName)
                .in(EduHouseDetail::getIdcard, allIdcardList)
                .eq(EduHouseDetail::getYear, eduStuEnrollPre.getYear())
                .select(EduHouseDetail::getHouseId);
        List<EduHouseDetail> houseDetailList=eduHouseDetailService.list(oldDetailQueryWrapper);
        Map<String, List<EduHouseDetail>> houseGroupBy = new HashMap<>();
        if(!CollectionUtils.isEmpty(houseDetailList)) {
            houseGroupBy=houseDetailList.stream().collect(Collectors.groupingBy(EduHouseDetail::getHouseId));
        }
        if (child != null) {
            LambdaQueryWrapper<EduHousehold> fmLambdaQueryWrapper = new LambdaQueryWrapper<>();
            fmLambdaQueryWrapper.select(EduHousehold::getIdcard).eq(EduHousehold::getYear, eduStuEnrollPre.getYear())
                    .eq(EduHousehold::getHh, child.getHh())
                    .eq(EduHousehold::getAuthStatus, AuthStatusEnum.YES.getType())
                    .eq(EduHousehold::getStatus, BoolEnum.TRUE.getType());
            List<EduHousehold> hkList = eduHouseholdService.list(fmLambdaQueryWrapper);
            if (!CollectionUtils.isEmpty(hkList)) {
                for (EduHousehold hk : hkList) {
                    if (StringUtils.isNotBlank(hk.getIdcard())) {
                        if (StringUtils.isNotBlank(eduStuEnrollPre.getFatherIdcard()) && eduStuEnrollPre.getFatherIdcard().equalsIgnoreCase(hk.getIdcard())) {
                            faFlag = true;
                        }
                        if (StringUtils.isNotBlank(eduStuEnrollPre.getMotherIdcard()) && eduStuEnrollPre.getMotherIdcard().equalsIgnoreCase(hk.getIdcard())) {
                            moFlag = true;
                        }
                    }
                }
            }
        }else{
            if (CollectionUtils.isEmpty(houseDetailList)) {
                //已同步没有户籍和没有房产的，不必对
                return "9";
            }
        }

        //父母和孩子都在同一个身份证
        if (faFlag&&faFlag) {
            return "1";
        }
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("cszm_batch_flag");
        commonVO.setAreaCode(areaCode);
        String cszmFlag = commonIntegration.getValueByKeyAndArea(commonVO);
        if(StringUtils.isBlank(cszmFlag)){
            cszmFlag="0";
        }
        if(faFlag&&!moFlag){
            if(haveMotherIDFlag){
                //先判断是否同房产证
                if (!CollectionUtils.isEmpty(houseGroupBy)) {
                    for(String houseId:houseGroupBy.keySet()){
                        List<EduHouseDetail> details=houseGroupBy.get(houseId);
                        boolean fatherFlag=false;
                        boolean motherFlag=false;
                        for(EduHouseDetail detail:details){
                            if (StringUtils.isNotBlank(detail.getIdcard())){
                                if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getFatherIdcard())){
                                    fatherFlag=true;
                                }
                                if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getMotherIdcard())){
                                    motherFlag=true;
                                }
                            }else{
                                if(StringUtils.isNotBlank(detail.getFullName())){
                                    if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFatherName())){
                                        fatherFlag=true;
                                    }
                                    if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFatherName())){
                                        motherFlag=true;
                                    }
                                }
                            }
                        }
                        if(fatherFlag&&motherFlag){
                            infoComparison="1";
                            break;
                        }
                    }
                    if(infoComparison.equalsIgnoreCase("1")){
                        return "1";
                    }
                }
                //不在同房产的情况下 判断出生证
                if("1".equalsIgnoreCase(cszmFlag)){
                    cszmQueryVO.setMsfz(eduStuEnrollPre.getMotherIdcard());
                    cszmQueryVO.setFsfz("");
                    List<CszmVO> mother = dygxIntegration.getCszm(cszmQueryVO);
                    if (mother.size() != 0) {
                        return "1";
                    }
                }

                return "2";
            }else{
                return "1";
            }

        }else if(!faFlag&&moFlag){
            if(haveFatherIDFlag){
                //先判断是否同房产证
                if (!CollectionUtils.isEmpty(houseGroupBy)) {
                    for(String houseId:houseGroupBy.keySet()){
                        List<EduHouseDetail> details=houseGroupBy.get(houseId);
                        boolean fatherFlag=false;
                        boolean motherFlag=false;
                        for(EduHouseDetail detail:details){
                            if (StringUtils.isNotBlank(detail.getIdcard())){
                                if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getFatherIdcard())){
                                    fatherFlag=true;
                                }
                                if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getMotherIdcard())){
                                    motherFlag=true;
                                }
                            }else{
                                if(StringUtils.isNotBlank(detail.getFullName())){
                                    if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFatherName())){
                                        fatherFlag=true;
                                    }
                                    if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFatherName())){
                                        motherFlag=true;
                                    }
                                }
                            }
                        }
                        if(fatherFlag&&motherFlag){
                            infoComparison="1";
                            break;
                        }
                    }
                    if(infoComparison.equalsIgnoreCase("1")){
                        return "1";
                    }
                }
                if("1".equalsIgnoreCase(cszmFlag)) {
                    cszmQueryVO.setMsfz("");
                    cszmQueryVO.setFsfz(eduStuEnrollPre.getFatherIdcard());
                    List<CszmVO> father = dygxIntegration.getCszm(cszmQueryVO);
                    if (father.size() != 0) {
                        return "1";
                    }
                }
                return "3";
            }else{
                return "1";
            }
        }else {
            //先判断是否同房产证
            if (!CollectionUtils.isEmpty(houseGroupBy)) {
                for (String houseId : houseGroupBy.keySet()) {
                    List<EduHouseDetail> details = houseGroupBy.get(houseId);
                    boolean fatherFlag = false;
                    boolean motherFlag = false;
                    boolean childFlag = false;
                    for (EduHouseDetail detail : details) {
                        if (StringUtils.isNotBlank(detail.getIdcard())) {
                            if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getFatherIdcard())) {
                                fatherFlag = true;
                            }
                            if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getMotherIdcard())) {
                                motherFlag = true;
                            }
                            if (detail.getIdcard().equalsIgnoreCase(eduStuEnrollPre.getIdcard())) {
                                childFlag = true;
                            }
                        } else {
                            if (StringUtils.isNotBlank(detail.getFullName())) {
                                if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFatherName())) {
                                    fatherFlag = true;
                                }
                                if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFatherName())) {
                                    motherFlag = true;
                                }
                                if (detail.getFullName().equalsIgnoreCase(eduStuEnrollPre.getFullName())) {
                                    childFlag = true;
                                }
                            }
                        }
                    }
                    if (fatherFlag && motherFlag && childFlag) {
                        infoComparison = "1";
                        break;
                    }
                }
                if (infoComparison.equalsIgnoreCase("1")) {
                    return "1";
                }
            }
            if ("1".equalsIgnoreCase(cszmFlag)) {
                //比对出生证信息
                // 1 通过 2 只有父亲通过 3 只有母亲通过 4 不通过 5 错误
                if (haveStuNameFlag && haveFatherIDFlag && haveMotherIDFlag) {
                    cszmQueryVO.setFsfz(eduStuEnrollPre.getFatherIdcard().trim());
                    cszmQueryVO.setMsfz(eduStuEnrollPre.getMotherIdcard().trim());

                    List<CszmVO> all = dygxIntegration.getCszm(cszmQueryVO);
                    if (all.size() != 0) {
                        return "1";
                    } else {
                        String errorFlag = "4";
                        cszmQueryVO.setMsfz("");
                        cszmQueryVO.setFsfz(eduStuEnrollPre.getFatherIdcard());
                        List<CszmVO> father = dygxIntegration.getCszm(cszmQueryVO);
                        boolean fatherFlag = false;
                        if (father.size() != 0) {
                            fatherFlag = true;
                        }
                        cszmQueryVO.setMsfz(eduStuEnrollPre.getMotherIdcard());
                        cszmQueryVO.setFsfz("");
                        List<CszmVO> mother = dygxIntegration.getCszm(cszmQueryVO);
                        boolean motherFlag = false;
                        if (mother.size() != 0) {
                            motherFlag = true;
                        }
                        if (fatherFlag && motherFlag) {
                            return "1";
                        } else if (fatherFlag && !motherFlag) {
                            return "2";
                        } else if (!fatherFlag && motherFlag) {
                            return "3";
                        } else {
                            return "4";
                        }
                    }
                } else {
                    if (haveStuNameFlag && haveMotherIDFlag) {
                        cszmQueryVO.setMsfz(eduStuEnrollPre.getMotherIdcard());
                        cszmQueryVO.setFsfz("");
                        List<CszmVO> mother = dygxIntegration.getCszm(cszmQueryVO);
                        if (mother.size() != 0) {
                            return "1";
                        } else {
                            return "4";
                        }
                    }
                    if (haveStuNameFlag && haveFatherIDFlag) {
                        cszmQueryVO.setMsfz("");
                        cszmQueryVO.setFsfz(eduStuEnrollPre.getFatherIdcard());
                        List<CszmVO> father = dygxIntegration.getCszm(cszmQueryVO);
                        if (father.size() != 0) {
                            return "1";
                        } else {
                            return "4";
                        }
                    }
                }
            }
        }
        return "4";
    }

    public String saveDict(String dictField, String dictValue, String accessToken) {
        if (ObjectUtils.isEmpty(dictValue)) {
            return dictValue;
        }
        DictQueryVO dictQueryVO = new DictQueryVO();
        dictQueryVO.setDictField(dictField);
        dictQueryVO.setDictValue(dictValue);
        String key = dictIntegration.getKey(dictQueryVO);
        if (!ObjectUtils.isEmpty(key)) {
            return key;
        } else {
            List<SelectVO> dictList = dictIntegration.getDictByDictField(dictQueryVO);
            int maxKey =
                    dictList.stream()
                            .mapToInt(item -> Integer.parseInt(item.getDictKey()))
                            .max()
                            .getAsInt();
            DictVO dictVO = Convert.convert(DictVO.class, dictList.get(0));
            dictVO.setSysId(null);
            dictVO.setDictKey(maxKey + 1 + "");
            dictVO.setDictValue(dictValue);
            dictVO.setAccessToken(accessToken);
            dictIntegration.add(dictVO);
            return dictVO.getDictKey();
        }
    }

    private List<EduCompanyVO> getQyInterface(String tyxydm, Integer year, Boolean replaceFlag) {
        QyQueryVO qyQueryVO = new QyQueryVO();
        qyQueryVO.setTyxydm(tyxydm);
        List<QyVO> qy = dygxIntegration.getQy(qyQueryVO);
        List<EduCompany> companyList = Convert.toList(EduCompany.class, qy);
        QueryWrapper<EduCompany> companyQueryWrapper = new QueryWrapper<>();
        companyQueryWrapper
                .lambda()
                .eq(EduCompany::getTyxydm, tyxydm)
                .isNull(EduCompany::getSchoolId)
                .eq(EduCompany::getYear, year);
        List<EduCompany> oldList = eduCompanyService.list(companyQueryWrapper);
        if (oldList.size() > 0) {
            if (replaceFlag) {
                eduCompanyService.removeByIds(
                        oldList.stream()
                                .map(EduCompany::getCompanyId)
                                .collect(Collectors.toList()));
            } else {
                return Convert.toList(EduCompanyVO.class, oldList);
            }
        }
        companyList.forEach(
                item -> {
                    item.setCompanyId(IdUtil.simpleUUID());
                    item.setYear(year);
                });
        eduCompanyService.saveBatch(companyList);
        return Convert.toList(EduCompanyVO.class, companyList);
    }

    //批量生成，循环处理，每次500条
    private void createBatchPageInfo(BatchCreateVO vo) {

        if (StringUtils.isNotBlank(vo.getBeforeFlag()) && BoolEnum.TRUE.getType().equals(vo.getBeforeFlag())) {
            throw new AppException("成功数据不能重新比对");
        } else {
            if (vo.getPageNum() != null && vo.getPageNum() > 30) {
                return;
            }

        }
        //房产户籍都获取大数据的情况下才能进行预报名生成
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getHouseSyncFlag, BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollPre::getHouseholdSyncFlag, BoolEnum.TRUE.getType());
        if (StringUtils.isBlank(vo.getBeforeFlag())) {
            queryWrapper.lambda().eq(EduStudentEnrollPre::getBeforeFlag, "0");
        } else {
            queryWrapper.lambda().eq(EduStudentEnrollPre::getBeforeFlag, vo.getBeforeFlag());
        }
        int pageNum = 1;
        int pageSize = 1000;
        PageHelper.startPage(pageNum, pageSize);
        List<EduStudentEnrollPre> list = eduStudentEnrollPreService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        PageInfo<EduStudentEnrollPre> prePageInfo = new PageInfo<>(list);
        for (EduStudentEnrollPre eduStudentEnrollPre : prePageInfo.getList()) {
            createBefore(eduStudentEnrollPre);
            eduEnrollClearCacheHelper.clearCachePreBefore(eduStudentEnrollPre.getStudentEnrollPreId());
        }
        if (prePageInfo.isHasNextPage()) {
            vo.setPageNum(vo.getPageNum() == null ? 1 : vo.getPageNum() + 1);
            vo.setPageSize(pageSize);
            this.createBatchPageInfo(vo);

        }
    }

    public int createBefore(EduStudentEnrollPre eduStudentEnrollPre) {
        String beforeFlag = "0";
        String msg = "成功";
        int count = 0;
        boolean isIdcard = IdcardUtil.isValidCard(eduStudentEnrollPre.getIdcard());
        if (StringUtils.isBlank(eduStudentEnrollPre.getCardType())) {
            if (isIdcard) {
                eduStudentEnrollPre.setCardType(CardTypeEnum.idcard.getType());
            } else {
                eduStudentEnrollPre.setCardType("99");
            }
        }
        if (isIdcard) {
            if (eduStudentEnrollPre.getAge() == null) {
                eduStudentEnrollPre.setAge(IdcardUtil.getAgeByIdCard(eduStudentEnrollPre.getIdcard(), DateUtil.parse(eduStudentEnrollPre.getYear() + "0831", "yyyyMMdd")));
            }
            if (StringUtils.isBlank(eduStudentEnrollPre.getBirthYmd())) {
                eduStudentEnrollPre.setBirthYmd(IdcardUtil.getBirth(eduStudentEnrollPre.getIdcard()));
            }
            if (StringUtils.isBlank(eduStudentEnrollPre.getSex())) {
                int gender = IdcardUtil.getGenderByIdCard(eduStudentEnrollPre.getIdcard());
                if (gender == 1) {
                    // 男
                    eduStudentEnrollPre.setSex("1");
                } else {
                    // 女
                    eduStudentEnrollPre.setSex("2");
                }
            }
        } else {
            if (eduStudentEnrollPre.getAge() == null) {
                if (StringUtils.isNotBlank(eduStudentEnrollPre.getBirthYmd())) {
                    if (eduStudentEnrollPre.getBirthYmd().length() >= 8) {
                        eduStudentEnrollPre.setAge(DateUtil.age(DateUtil.parse(eduStudentEnrollPre.getBirthYmd().replaceAll("-", "").replaceAll("/", ""), "yyyyMMdd"), DateUtil.parse(eduStudentEnrollPre.getYear() + "0831", "yyyyMMdd")));
                    } else if (eduStudentEnrollPre.getBirthYmd().length() == 6) {
                        eduStudentEnrollPre.setAge(DateUtil.age(DateUtil.parse(eduStudentEnrollPre.getBirthYmd() + "01", "yyyyMMdd"), DateUtil.parse(eduStudentEnrollPre.getYear() + "0831", "yyyyMMdd")));
                    }

                }

            }
        }
        try {
            count = dyEnrollBeforeCreateHelper.createEnrollBefore(eduStudentEnrollPre);
            if (count > 0) {
                beforeFlag = "1";
            } else {
                beforeFlag = "3";
            }

        } catch (AppException e) {
            logger.error("生成预报名失败："+e.getMsg());
            beforeFlag = "2";
            msg = e.getMsg();
        } catch (Exception e) {
            logger.error("生成预报名失败："+e.getMessage());
            beforeFlag = "2";
            msg = e.getMessage();

        }
        if (msg.length() > 200) {
            msg = msg.substring(0, 200);
        }

        eduStudentEnrollPre.setBeforeFlag(beforeFlag);
        eduStudentEnrollPre.setBeforeRemark(msg);
        if (StringUtils.isNotBlank(eduStudentEnrollPre.getFullName())) {
            eduStudentEnrollPre.setFullName(eduStudentEnrollPre.getFullName().trim());
        }
        if (StringUtils.isNotBlank(eduStudentEnrollPre.getMotherName())) {
            eduStudentEnrollPre.setMotherName(eduStudentEnrollPre.getMotherName().trim());
        }
        if (StringUtils.isNotBlank(eduStudentEnrollPre.getFatherName())) {
            eduStudentEnrollPre.setFatherName(eduStudentEnrollPre.getFatherName().trim());
        }
        eduStudentEnrollPreService.updateById(eduStudentEnrollPre);
        return count;
    }

    //批量预测生成，循环处理，每次500条
    private void createCalculateBatchPageInfo(BatchCreateVO vo) {

        if (StringUtils.isNotBlank(vo.getCalculateFlag()) && BoolEnum.TRUE.getType().equals(vo.getCalculateFlag())) {
            throw new AppException("成功数据不能重新比对");
        } else {
            if (vo.getPageNum() != null && vo.getPageNum() > 30) {
                return;
            }
        }
        //房产户籍都获取大数据的情况下才能进行预报名生成
        QueryWrapper<EduStudentEnrollPre> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EduStudentEnrollPre::getAuthStatus, AuthStatusEnum.YES.getType())
                .eq(EduStudentEnrollPre::getHouseSyncFlag, BoolEnum.TRUE.getType())
                .eq(EduStudentEnrollPre::getHouseholdSyncFlag, BoolEnum.TRUE.getType());
        if (StringUtils.isBlank(vo.getCalculateFlag())) {
            queryWrapper.lambda().eq(EduStudentEnrollPre::getCalculateFlag, "0");
        } else {
            queryWrapper.lambda().eq(EduStudentEnrollPre::getCalculateFlag, vo.getCalculateFlag());
        }
        int pageNum = 1;
        int pageSize = 1000;
        PageHelper.startPage(pageNum, pageSize);
        List<EduStudentEnrollPre> list = eduStudentEnrollPreService.list(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return;
        }
        PageInfo<EduStudentEnrollPre> prePageInfo = new PageInfo<>(list);
        for (EduStudentEnrollPre eduStudentEnrollPre : prePageInfo.getList()) {
            createCalculate(eduStudentEnrollPre);
        }
        if (prePageInfo.isHasNextPage()) {
            vo.setPageNum(vo.getPageNum() == null ? 1 : vo.getPageNum() + 1);
            vo.setPageSize(pageSize);
            this.createCalculateBatchPageInfo(vo);

        }
    }

    public int createCalculate(EduStudentEnrollPre eduStudentEnrollPre) {
        String beforeFlag = "0";
        String msg = "成功";
        int count = 0;

        try {
            count = dyEnrollCalculateCreateHelper.createEnrollBefore(eduStudentEnrollPre);
            if (count > 0) {
                beforeFlag = "1";
            } else {
                beforeFlag = "3";
            }

        } catch (AppException e) {
            logger.error("生成预报名失败："+e.getMsg());
            beforeFlag = "2";
            msg = e.getMsg();
        } catch (Exception e) {
            logger.error("生成预报名失败："+e.getMessage());
            beforeFlag = "2";
            msg = e.getMessage();

        }
        if (msg.length() > 200) {
            msg = msg.substring(0, 200);
        }

        eduStudentEnrollPre.setCalculateFlag(beforeFlag);
        eduStudentEnrollPre.setCalculateRemark(msg);
        eduStudentEnrollPreService.updateById(eduStudentEnrollPre);
        return count;
    }

    @Override
    @OpApi(funcCode = "F3307830011", title = "大数据户籍接口信息获取", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduHouseholdVO> queryBigDataHousehold(HouseHoldSaveVO vo) {
        List<EduHouseholdVO> eduHouseholdVOList = new ArrayList<>();
        if (ObjectUtils.isEmpty(vo.getIdcard())) {
            return null;
        }
        if(vo.getLocalFlag()==null){
            vo.setLocalFlag(true);
        }
        try {
            if (vo.getLocalFlag()) {
                List<DyHouseholdVO> dyHouseholdVOList=dygxIntegration.getDyHjInfo(vo.getIdcard(),vo.getReqIp());

                if (dyHouseholdVOList != null && dyHouseholdVOList.size() > 0) {
                    for(DyHouseholdVO item:dyHouseholdVOList) {
                        EduHouseholdVO eduHousehold = new EduHouseholdVO();
                        eduHousehold.setHouseholdId(IdUtil.simpleUUID());
                        eduHousehold.setHhid(item.getHhid());
                        eduHousehold.setHh(item.getHh());
                        eduHousehold.setAccountType(item.getHb());
                        eduHousehold.setIdcard(item.getGmsfhm().toUpperCase());
                        eduHousehold.setFullName(item.getXm());
                        eduHousehold.setBeforeName(item.getCym());
                        eduHousehold.setSex(item.getXb());
                        eduHousehold.setBirthday(item.getCsrq());
                        eduHousehold.setNation(item.getMz());
                        eduHousehold.setNativePlace(item.getJgssxq());
                        eduHousehold.setBirthplace(item.getCsdssxq());
                        eduHousehold.setAddressCity(item.getHkszdxs());
                        eduHousehold.setAddressCountry(item.getHkszxzjd());
                        eduHousehold.setAddressVillage(item.getHkszdjcwh());
                        eduHousehold.setAddressVillageDetail(item.getHkszdjlx());
                        eduHousehold.setMlxz(item.getMlxz());
                        eduHousehold.setMlph(item.getMlph());
                        eduHousehold.setAddress(item.getHkAdreess());
                        eduHousehold.setHssqlbz(item.getHssqlbz());
                        eduHousehold.setHssqxqlws(item.getHssqxqlws());
                        eduHousehold.setHxzlbd(item.getHxzlbd());
                        eduHousehold.setHsqlbs(item.getHsqlbs());
                        eduHousehold.setHsqlbz(item.getHsqlbz());
                        eduHousehold.setQysj(item.getQysj());
                        eduHousehold.setJlbz(item.getJlbz());
                        eduHousehold.setRyzt(item.getRyzt());
                        eduHousehold.setRyid(item.getRyid());
                        eduHousehold.setYxqxqsrq(item.getYxqxqsrq());
                        eduHousehold.setYxqxjzrq(item.getYxqxjzrq());
                        eduHousehold.setPcs(item.getPcs());
                        eduHousehold.setQfjg(item.getQfjg());
                        eduHousehold.setRelation(item.getYhzgx());
                        eduHousehold.setXxqysj(item.getXxqysj());
                        eduHousehold.setAuthStatus(AuthStatusEnum.YES.getType());
                        eduHousehold.setStatus(BoolEnum.TRUE.getType());
                        eduHousehold.setAreaCode(areaCode);
                        eduHouseholdVOList.add(eduHousehold);
                    }
                }
            } else {
                JSONArray jsonArray = dygxIntegration.getFamilyInfo(vo.getIdcard());
                if (jsonArray != null && jsonArray.size() > 0) {
                    jsonArray.forEach(
                            item -> {
                                JSONObject personData = (JSONObject) item;
                                EduHouseHoldInterfaceVO holdInterfaceVO =
                                        personData
                                                .getJSONObject("ELC_LICENCE_STRUCT")
                                                .getObject("DATA", EduHouseHoldInterfaceVO.class);
                                String elcLicenceName = (String) personData.get("ELC_LICENCE_NAME");
                                holdInterfaceVO.setElcLicenceName(elcLicenceName);

                                EduHouseholdVO eduHousehold = new EduHouseholdVO();
                                eduHousehold.setHouseholdId(IdUtil.simpleUUID());
                                eduHousehold.setHhid(holdInterfaceVO.getCZRKHHID());
                                eduHousehold.setHh(holdInterfaceVO.getCZRKHH());
                                eduHousehold.setIdcard(holdInterfaceVO.getCZRKGMSFHM());
                                eduHousehold.setFullName(holdInterfaceVO.getCZRKXM());
                                eduHousehold.setAddress(holdInterfaceVO.getCZRKZZ());
                                eduHousehold.setBirthday(holdInterfaceVO.getCZRKCSRQ());
                                eduHousehold.setSex(holdInterfaceVO.getCZRKXB());
                                eduHousehold.setCountry(holdInterfaceVO.getCZRKJGGJ());
                                eduHousehold.setBirthplace(holdInterfaceVO.getCZRKCSDSSX());
                                eduHousehold.setNativePlace(holdInterfaceVO.getCZRKJGSSX());
                                eduHousehold.setHouseholdPlace(holdInterfaceVO.getCZRKZZ());
                                eduHousehold.setAccountType(holdInterfaceVO.getElcLicenceName());
                                eduHousehold.setRelation(holdInterfaceVO.getCZRKYHZGX());
                                eduHousehold.setHouseholder(holdInterfaceVO.getCZRKHZXM());
                                eduHousehold.setServiceSpaces(holdInterfaceVO.getCZRKFWCS());
                                eduHousehold.setHsqlbz(holdInterfaceVO.getCZRKHSQLBS());
                                eduHousehold.setHssqlbz(holdInterfaceVO.getCZRKHZQLSSX());
                                eduHousehold.setHssqxqlws(holdInterfaceVO.getCZRKHDQLXZ());
                                eduHousehold.setHxzlbd(holdInterfaceVO.getCZRKHZQLXZ());
                                eduHousehold.setHsqlbs(holdInterfaceVO.getCZRKHZQLSSX());
                                if (eduHousehold.getAddress().indexOf("东阳") >= 0) {
                                    //地址中包含东阳的就认为是东阳市地址
                                    eduHousehold.setAreaCode(areaCode);
                                }
                                if (StringUtils.isNotBlank(holdInterfaceVO.getCZRKHSQLBZ())) {
                                    try {
                                        if (holdInterfaceVO.getCZRKHSQLBZ().length() == 8) {
                                            eduHousehold.setRegistrationDate(DatePattern.PURE_DATE_FORMAT.parse(holdInterfaceVO.getCZRKHSQLBZ()));
                                        } else if (holdInterfaceVO.getCZRKHSQLBZ().length() == 10) {
                                            eduHousehold.setRegistrationDate(DatePattern.NORM_DATE_FORMAT.parse(holdInterfaceVO.getCZRKHSQLBZ()));
                                        }
                                    } catch (Exception e) {
                                        logger.error("户籍迁入时间格式转换异常"+e.getMessage());
                                    }

                                }
                                eduHouseholdVOList.add(eduHousehold);
                            });
                }
            }
        } catch (Exception e) {
            throw new AppException(e.getMessage());
        }
        return eduHouseholdVOList;
    }

    @Override
    @OpApi(funcCode = "F3307830012", title = "大数据房产接口信息获取", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduHouseVO> queryBigDataHouseInterface(HouseInterfaceSaveVO vo) {
        List<EduHouseVO> eduHouseVOList = new ArrayList<>();
        try {

            JSONArray houseArr = new JSONArray();
            JSONArray houseStArr = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard(),vo.getReqIp());
            if (houseStArr != null) {
                houseArr.addAll(houseStArr);
            }
            if (vo.getIdcard().indexOf("X") > 0) {
                JSONArray houseStArrX = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard().toLowerCase(),vo.getReqIp());
                if (houseStArrX != null) {
                    houseArr.addAll(houseStArrX);
                }
            }

            if (houseArr.size() > 0) {
                List<Map<String, String>> hasList = new ArrayList<>();
                List<String> hasBdcdyhList = new ArrayList<>();
                for (Object item : houseArr) {
                    HouseInterfaceVO house = Convert.convert(HouseInterfaceVO.class, item);
                    String realProperty = house.getQlrxxList().stream()
                            .map(HouseInterfaceDetailVO::getBdcqzh)
                            .distinct()
                            .collect(Collectors.joining(","));

                    if (!ObjectUtils.isEmpty(house.getBdcdyh())) {
                        if (hasBdcdyhList.contains(house.getBdcdyh())) {
                            continue;
                        }
                        hasBdcdyhList.add(house.getBdcdyh());
                    } else {
                        Map<String, String> realMap = new HashMap<>();
                        realMap.put("realProperty", realProperty);
                        realMap.put("zl", house.getZl());
                        boolean continueFlg = false;
                        for (Map<String, String> map : hasList) {
                            if (map.get("realProperty").equals(realProperty) && map.get("zl").equals(house.getZl())) {
                                continueFlg = true;
                                break;
                            }
                        }
                        if (continueFlg) {
                            continue;
                        }
                        hasList.add(realMap);
                    }

                    List<String> qlrList = new ArrayList<>();
                    String qlrName = "";
                    List<String> qlrNameList = new ArrayList<>();
                    for (HouseInterfaceDetailVO detailVO : house.getQlrxxList()) {
                        if (StringUtils.isBlank(detailVO.getZjh())) {
                        } else {
                            if (IdcardUtil.isValidCard(detailVO.getZjh())) {
                                if (detailVO.getZjh().length() == 15) {
                                    qlrList.add(IdcardUtil.convert15To18(detailVO.getZjh().toUpperCase()));
                                } else {
                                    qlrList.add(detailVO.getZjh().toUpperCase());
                                }
                            } else {
                                qlrList.add(detailVO.getZjh().toUpperCase());
                            }


                        }
                        qlrNameList.add(detailVO.getQlr());
                        if (StringUtils.isBlank(qlrName)) {
                            qlrName = detailVO.getQlr() + "(" + detailVO.getZjh() + ")";
                        } else {
                            qlrName = qlrName + "," + detailVO.getQlr() + "(" + detailVO.getZjh() + ")";
                        }
                    }
                    EduHouse eduHouse = new EduHouse();
                    eduHouse.setHouseId(IdUtil.simpleUUID());
                    eduHouse.setAddress(house.getZl());
                    if (!ObjectUtils.isEmpty(house.getDjsj())) {
                        eduHouse.setRegisterDate(
                                DateUtil.parse(house.getDjsj(), "yyyy年MM月dd日"));
                    }
                    if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                        eduHouse.setRealProperty(realProperty);
                    }
                    eduHouse.setRealPropertyNum(house.getBdcdyh());
                    if (!ObjectUtils.isEmpty(house.getTdsyqssj())) {
                        eduHouse.setBegDate(
                                DateUtil.parse(house.getTdsyqssj(), "yyyy年MM月dd日"));
                    }
                    if (!ObjectUtils.isEmpty(house.getTdsyjssj())) {
                        eduHouse.setEndDate(
                                DateUtil.parse(house.getTdsyjssj(), "yyyy年MM月dd日"));
                    }
                    String yt = house.getYt().replace("/", "").trim();
                    eduHouse.setLandCategories(
                            saveDict("LANDCATEGORIES", yt, vo.getAccessToken()));
                    eduHouse.setLandCategoriesName(yt);
                    eduHouse.setHouseNature(
                            saveDict("HOUSENATURE", house.getFwxz(), vo.getAccessToken()));
                    eduHouse.setHouseNatureName(house.getFwxz());
//                    eduHouse.setStatus("1");
//                    eduHouse.setAuthStatus(AuthStatusEnum.NODO.getType());
                    if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                        List<HouseInterfaceDetailVO> qlrxxList = house.getQlrxxList();
                        if (!ObjectUtils.isEmpty(house.getTdsyjssj())
                                && !ObjectUtils.isEmpty(house.getTdsyqssj())) {
                            int betweenYear =
                                    (int)
                                            DateUtil.betweenYear(
                                                    DateUtil.offsetDay(
                                                            DateUtil.parse(
                                                                    house.getTdsyqssj(),
                                                                    "yyyy年MM月dd日"),
                                                            -1),
                                                    DateUtil.parse(
                                                            house.getTdsyjssj(),
                                                            "yyyy年MM月dd日"),
                                                    false);
                            eduHouse.setYearLimit(betweenYear);
                        } else {
                            eduHouse.setYearLimit(100);
                        }
                        eduHouse.setQlrNum(qlrxxList.size());
                        eduHouse.setQlrName(qlrName);
                    }
                    eduHouseVOList.add(Convert.convert(EduHouseVO.class, eduHouse));
                }
            }
        } catch (Exception e) {
            logger.error("房产获取异常"+e.getMessage());
            throw new AppException(e.getMessage());
        }
        return eduHouseVOList;
    }

    @Override
    @OpApi(funcCode = "F3307830014", title = "义务段家长端报名保存", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void saveEnroll(SaveStudentEnrollVO vo) {
        String applyId = dyEnrollHelper.save(vo);
        vo.setApplyId(applyId);
    }

    @Override
    @OpApi(funcCode = "F3307830023", title = "义务段模拟报名保存", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void saveImitateEnroll(SaveStudentEnrollVO vo) {

    }

    //录取报名数据
    @Override
    @OpApi(funcCode = "F3307830015", title = "录取报名数据", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void unifiedSupervisionEnrollAdmit(EduJhjySync eduJhjySync) {
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_url");
        commonVO.setAreaCode(areaCode);
        String url = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(url)) {
            throw new AppException("金华教育监管平台接口地址参数未配置！(jhjy_sync_url)");
        }
        if (StringUtils.isBlank(eduJhjySync.getIdcard())) {
            throw new AppException("身份证不能为空");
        }
        if (eduJhjySync.getEduStage() == null) {
            throw new AppException("学段不能为空");
        }
        if (eduJhjySync.getSchoolType() == null) {
            throw new AppException("学校类型不能为空");
        }
        if (StringUtils.isBlank(eduJhjySync.getSchoolName())) {
            throw new AppException("学校名称不能为空");
        }
        url = url + "/OpenAPI/UnifiedSupervisionEnrollAdmit";
        JhjyLqVO jhjyLqVO = Convert.convert(JhjyLqVO.class, eduJhjySync);
        String body = JSON.toJSONString(jhjyLqVO);
        String request = getRequest(body);
        String retBody = send(url, request);
        if (StringUtils.isBlank(retBody)) {
            throw new AppException("金华教育录取上传接口，未返回信息");
        }
        JhjyRetVO retVO = null;
        try {
            retVO = JSON.parseObject(retBody, JhjyRetVO.class);
        } catch (Exception e) {
            throw new AppException("金华教育录取上传接口失败：" + body);
        }
        if (!"200".equals(retVO.getResult_code())) {
            throw new AppException(retVO.getMsg());
        }

    }

    //录取报名数据
    @Override
    @OpApi(funcCode = "F3307830016", title = "查询录取情况", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public String unifiedSupervisionEnrollSearchAdmit(JhjyQueryVO vo) {
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_url");
        commonVO.setAreaCode(areaCode);
        String url = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(url)) {
            throw new AppException("金华教育监管平台接口地址参数未配置！(jhjy_sync_url)");
        }
        if (StringUtils.isBlank(vo.getIdcard())) {
            throw new AppException("查询的身份证不能为空");
        }
        if (vo.getEduStage() == null) {
            throw new AppException("查询的学段不能为空");
        }
        url = url + "/OpenAPI/UnifiedSupervisionEnrollSearchAdmit";
        String body = JSON.toJSONString(vo);
        String request = getRequest(body);
        String retBody = send(url, request);
        if (StringUtils.isBlank(retBody)) {
            throw new AppException("金华教育查询上传接口，未返回信息");
        }
        JhjyRetVO retVO = null;
        try {
            retVO = JSON.parseObject(retBody, JhjyRetVO.class);
        } catch (Exception e) {
            throw new AppException("金华教育查询接口失败：" + body);
        }
        if (!"200".equals(retVO.getResult_code())) {
            throw new AppException(retVO.getMsg());
        }
        Object obj = retVO.getData();
        return obj.toString();

    }


    //录取报名数据
    @Override
    @OpApi(funcCode = "F3307830020", title = "报名数据上传", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void unifiedSupervisionEnrollAdd(EduJhjySync eduJhjySync) {
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_url");
        commonVO.setAreaCode(areaCode);
        String url= commonIntegration.getValueByKeyAndArea(commonVO);
        if(StringUtils.isBlank(url)){
            throw new AppException("金华教育监管平台接口地址参数未配置！(jhjy_sync_url)");
        }
        if(StringUtils.isBlank(eduJhjySync.getIdcard())){
            throw new AppException("身份证不能为空");
        }
        if(eduJhjySync.getEduStage()==null){
            throw new AppException("学段不能为空");
        }
        if(eduJhjySync.getSchoolType()==null){
            throw new AppException("学校类型不能为空");
        }
        if(StringUtils.isBlank(eduJhjySync.getSchoolName())){
            throw new AppException("学校名称不能为空");
        }
        url=url+"/OpenAPI/UnifiedSupervisionEnrollAdd";
        JhjyBmVO jhjyBmVO= Convert.convert(JhjyBmVO.class,eduJhjySync);
        String body= JSON.toJSONString(jhjyBmVO);
        String request=getRequest(body);
        String retBody=send(url,request);
        if (StringUtils.isBlank(retBody)) {
            throw new AppException("金华教育报名上传接口，未返回信息");
        }
        JhjyRetVO retVO=null;
        try{
            retVO= JSON.parseObject(retBody,JhjyRetVO.class);
        }catch (Exception e){
            throw new AppException("金华教育报名上传接口失败：" + body);
        }
        if(!"200".equals(retVO.getResult_code())){
            throw new AppException(retVO.getMsg());
        }

    }

    //录取报名数据
    @Override
    @OpApi(funcCode = "F3307830021", title = "报名数据删除", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void unifiedSupervisionEnrollDelete(EduJhjySync eduJhjySync) {
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_url");
        commonVO.setAreaCode(areaCode);
        String url= commonIntegration.getValueByKeyAndArea(commonVO);
        if(StringUtils.isBlank(url)){
            throw new AppException("金华教育监管平台接口地址参数未配置！(jhjy_sync_url)");
        }
        if(StringUtils.isBlank(eduJhjySync.getIdcard())){
            throw new AppException("身份证不能为空");
        }
        if(eduJhjySync.getEduStage()==null){
            throw new AppException("学段不能为空");
        }
        if(StringUtils.isBlank(eduJhjySync.getDeleteReason())){
            throw new AppException("删除理由不能为空");
        }
        url=url+"/OpenAPI/UnifiedSupervisionEnrollDelete";
        JhjyQxbmVO jhjyQxbmVO= Convert.convert(JhjyQxbmVO.class,eduJhjySync);
        String body= JSON.toJSONString(jhjyQxbmVO);
        String request=getRequest(body);
        String retBody=send(url,request);
        if (StringUtils.isBlank(retBody)) {
            throw new AppException("金华教育取消报名上传接口，未返回信息");
        }
        JhjyRetVO retVO=null;
        try{
            retVO=JSON.parseObject(retBody,JhjyRetVO.class);
        }catch (Exception e){
            throw new AppException("金华教育取消报名上传接口失败：" + body);
        }
        if(!"200".equals(retVO.getResult_code())){
            throw new AppException(retVO.getMsg());
        }
    }

    //录取报名数据
    @Override
    @OpApi(funcCode = "F3307830022", title = "取消录取报名数据", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public void unifiedSupervisionEnrollCancelAdmit(EduJhjySync eduJhjySync) {
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_url");
        commonVO.setAreaCode(areaCode);
        String url= commonIntegration.getValueByKeyAndArea(commonVO);
        if(StringUtils.isBlank(url)){
            throw new AppException("金华教育监管平台接口地址参数未配置！(jhjy_sync_url)");
        }
        if(StringUtils.isBlank(eduJhjySync.getIdcard())){
            throw new AppException("身份证不能为空");
        }
        if(eduJhjySync.getEduStage()==null){
            throw new AppException("学段不能为空");
        }
        url=url+"/OpenAPI/UnifiedSupervisionEnrollCancelAdmit";
        JhjyQxlqVO jhjyQxlqVO= Convert.convert(JhjyQxlqVO.class,eduJhjySync);
        String body= JSON.toJSONString(jhjyQxlqVO);
        String request=getRequest(body);
        String retBody=send(url,request);
        if (StringUtils.isBlank(retBody)) {
            throw new AppException("金华教育取消录取上传接口，未返回信息");
        }
        JhjyRetVO retVO=null;
        try{
            retVO= JSON.parseObject(retBody,JhjyRetVO.class);
        }catch (Exception e){
            throw new AppException("金华教育取消录取上传接口失败：" + body);
        }
        if(!"200".equals(retVO.getResult_code())){
            throw new AppException(retVO.getMsg());
        }
    }

    //获取请求体
    private String getRequest(String body) {
        if (StringUtils.isBlank(body)) {
            throw new AppException("调用金华教育接口请求体不能为空");
        }
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_jmsy");
        commonVO.setAreaCode(areaCode);
        String PRIVATE_KEY = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(PRIVATE_KEY)) {
            throw new AppException("金华教育监管平台接口加密私钥参数未配置！(jhjy_sync_jmsy)");
        }
        RSA rsa_de = new RSA(PRIVATE_KEY, null);
        byte[] encrypt = rsa_de.encrypt(body, KeyType.PrivateKey);
        return Base64.encode(encrypt);
    }

    //发送信息
    private String send(String url, String request) {
        Map<String, Object> map = new HashMap<>();
        CommonVO commonVO = new CommonVO();
        commonVO.setParamKey("jhjy_sync_app_key");
        commonVO.setAreaCode(areaCode);
        String appKey = commonIntegration.getValueByKeyAndArea(commonVO);
        if (StringUtils.isBlank(appKey)) {
            throw new AppException("金华教育监管平台接口参数未配置！(jhjy_sync_app_key)");
        }
        CommonVO commonVO2 = new CommonVO();
        commonVO2.setParamKey("jhjy_sync_app_secret");
        commonVO2.setAreaCode(areaCode);
        String appSecret = commonIntegration.getValueByKeyAndArea(commonVO2);
        if (StringUtils.isBlank(appSecret)) {
            throw new AppException("金华教育监管平台接口参数未配置！(jhjy_sync_app_secret)");
        }
        map.put("appKey", appKey);
        map.put("request", request);
        String sign = SecureUtil.md5(request + appSecret);
        map.put("sign", sign);
        String ret = HttpRequest.post(url)
                .form(map)//表单内容
                .timeout(10000)//超时，毫秒
                .execute().body();
        return ret;

    }

    @Override
    @OpApi(funcCode = "F3307830017", title = "大数据企业接口信息获取", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduCompanyVO> queryQyInterfaceData(QySearchVO vo) {
        int year = operationCacheIntegration.getPeriodYear().getYear();
        String tyxydm = vo.getTyxydm();
        QyQueryVO qyQueryVO = new QyQueryVO();
        qyQueryVO.setTyxydm(tyxydm);
        List<QyVO> qy = dygxIntegration.getQy(qyQueryVO);
        List<EduCompany> companyList = Convert.toList(EduCompany.class, qy);
        companyList.forEach(
                item -> {
                    item.setCompanyId(IdUtil.simpleUUID());
                    item.setYear(year);
                });
        return Convert.toList(EduCompanyVO.class, companyList);
    }

    @Override
    @OpApi(funcCode = "F3307830018", title = "特殊通道人员维护房产大数据获取", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduHouseVO> queryEnrollBeforeHouse(HouseInterfaceSaveVO vo) {
        List<EduHouseVO> eduHouseVOList = new ArrayList<>();
        try {

            JSONArray houseArr = new JSONArray();
            JSONArray houseStArr = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard(),vo.getReqIp());
            if (houseStArr != null) {
                houseArr.addAll(houseStArr);
            }
            if (vo.getIdcard().indexOf("X") > 0) {
                JSONArray houseStArrX = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard().toLowerCase(),vo.getReqIp());
                if (houseStArrX != null) {
                    houseArr.addAll(houseStArrX);
                }
            }

            if (houseArr.size() > 0) {
                List<Map<String, String>> hasList = new ArrayList<>();
                List<String> hasBdcdyhList = new ArrayList<>();
                for (Object item : houseArr) {
                    HouseInterfaceVO house = Convert.convert(HouseInterfaceVO.class, item);
                    String realProperty = house.getQlrxxList().stream()
                            .map(HouseInterfaceDetailVO::getBdcqzh)
                            .distinct()
                            .collect(Collectors.joining(","));

                    if (!ObjectUtils.isEmpty(house.getBdcdyh())) {
                        if (hasBdcdyhList.contains(house.getBdcdyh())) {
                            continue;
                        }
                        hasBdcdyhList.add(house.getBdcdyh());
                    } else {
                        Map<String, String> realMap = new HashMap<>();
                        realMap.put("realProperty", realProperty);
                        realMap.put("zl", house.getZl());
                        boolean continueFlg = false;
                        for (Map<String, String> map : hasList) {
                            if (map.get("realProperty").equals(realProperty) && map.get("zl").equals(house.getZl())) {
                                continueFlg = true;
                                break;
                            }
                        }
                        if (continueFlg) {
                            continue;
                        }
                        hasList.add(realMap);
                    }

                    List<String> qlrList = new ArrayList<>();
                    String qlrName = "";
                    List<String> qlrNameList = new ArrayList<>();
                    for (HouseInterfaceDetailVO detailVO : house.getQlrxxList()) {
                        if (StringUtils.isBlank(detailVO.getZjh())) {
                        } else {

                            if (IdcardUtil.isValidCard(detailVO.getZjh())) {
                                if (detailVO.getZjh().length() == 15) {
                                    qlrList.add(IdcardUtil.convert15To18(detailVO.getZjh().toUpperCase()));
                                } else {
                                    qlrList.add(detailVO.getZjh().toUpperCase());
                                }
                            } else {
                                qlrList.add(detailVO.getZjh().toUpperCase());
                            }

                        }
                        qlrNameList.add(detailVO.getQlr());
                        if (StringUtils.isBlank(qlrName)) {
                            qlrName = detailVO.getQlr() + "(" + detailVO.getZjh() + ")";
                        } else {
                            qlrName = qlrName + "," + detailVO.getQlr() + "(" + detailVO.getZjh() + ")";
                        }
                    }
                    EduHouse eduHouse = new EduHouse();
                    // eduHouse.setHouseId(IdUtil.simpleUUID());
                    eduHouse.setAddress(house.getZl());
                    if (!ObjectUtils.isEmpty(house.getDjsj())) {
                        eduHouse.setRegisterDate(
                                DateUtil.parse(house.getDjsj(), "yyyy年MM月dd日"));
                    }
                    if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                        eduHouse.setRealProperty(realProperty);
                    }
                    eduHouse.setRealPropertyNum(house.getBdcdyh());
                    if (!ObjectUtils.isEmpty(house.getTdsyqssj())) {
                        eduHouse.setBegDate(
                                DateUtil.parse(house.getTdsyqssj(), "yyyy年MM月dd日"));
                    }
                    if (!ObjectUtils.isEmpty(house.getTdsyjssj())) {
                        eduHouse.setEndDate(
                                DateUtil.parse(house.getTdsyjssj(), "yyyy年MM月dd日"));
                    }
                    String yt = house.getYt().replace("/", "").trim();
                    eduHouse.setLandCategories(
                            saveDict("LANDCATEGORIES", yt, vo.getAccessToken()));
                    eduHouse.setLandCategoriesName(yt);
                    eduHouse.setHouseNature(
                            saveDict("HOUSENATURE", house.getFwxz(), vo.getAccessToken()));
                    eduHouse.setHouseNatureName(house.getFwxz());
//                    eduHouse.setStatus("1");
//                    eduHouse.setAuthStatus(AuthStatusEnum.NODO.getType());
                    if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                        List<HouseInterfaceDetailVO> qlrxxList = house.getQlrxxList();
                        if (!ObjectUtils.isEmpty(house.getTdsyjssj())
                                && !ObjectUtils.isEmpty(house.getTdsyqssj())) {
                            int betweenYear =
                                    (int)
                                            DateUtil.betweenYear(
                                                    DateUtil.offsetDay(
                                                            DateUtil.parse(
                                                                    house.getTdsyqssj(),
                                                                    "yyyy年MM月dd日"),
                                                            -1),
                                                    DateUtil.parse(
                                                            house.getTdsyjssj(),
                                                            "yyyy年MM月dd日"),
                                                    false);
                            eduHouse.setYearLimit(betweenYear);
                        } else {
                            eduHouse.setYearLimit(100);
                        }
                        eduHouse.setQlrNum(qlrxxList.size());
                        eduHouse.setQlrName(qlrName);
                    }
                    EduHouseVO eduHouseVO = Convert.convert(EduHouseVO.class,eduHouse);
                    eduHouseVO.setHouseInterfaceVO(house);
                    eduHouseVOList.add(eduHouseVO);
                }
            }
        } catch (Exception e) {
            logger.error("房产获取异常"+e.getMessage());
            throw new AppException(e.getMessage());
        }
        return eduHouseVOList;
    }

    @Override
    @OpApi(funcCode = "F3307830019", title = "东阳幼儿园房产接口信息获取并保存", funcType = FuncTypeEnum.query, checkPrivilege = BoolEnum.FALSE, savelog = false)
    public List<EduHouseVO> saveHouseNurseryInterfaceData(HouseInterfaceSaveVO vo) {
        List<EduHouseVO> eduHouseVOList = new ArrayList<>();
        try {
            int year = 0;
            year = eduHelper.thisYear();
            QueryWrapper<EduHouseDetailNursery> oldDetailQueryWrapper = new QueryWrapper<>();
            oldDetailQueryWrapper
                    .lambda()
                    .eq(EduHouseDetailNursery::getIdcard, vo.getIdcard())
                    .eq(EduHouseDetailNursery::getFullName, vo.getName())
                    .eq(EduHouseDetailNursery::getYear, year)
                    .select(EduHouseDetailNursery::getHouseId);
            List<String> houseIdList =
                    eduHouseDetailNurseryService.list(oldDetailQueryWrapper).stream()
                            .map(EduHouseDetailNursery::getHouseId)
                            .collect(Collectors.toList());
            if (houseIdList.size() > 0) {
                eduHouseDetailNurseryService.removeByIds(houseIdList);
                eduHouseNurseryService.removeByIds(houseIdList);
            }
            JSONArray houseArr = dygxIntegration.getPersonHouse(vo.getName(), vo.getIdcard(),vo.getReqIp());
            if (houseArr.size() > 0) {
                int finalYear = year;
                houseArr.forEach(
                        item -> {
                            HouseInterfaceVO house = Convert.convert(HouseInterfaceVO.class, item);
                            String realProperty =
                                    house.getQlrxxList().stream()
                                            .map(HouseInterfaceDetailVO::getBdcqzh)
                                            .collect(Collectors.joining(","));
                            QueryWrapper<EduHouseNursery> houseQueryWrapper = new QueryWrapper<>();
                            EduHouseNursery odlHouse = null;
                            if (ObjectUtils.isEmpty(house.getBdcdyh())) {
                                QueryWrapper<EduHouseDetailNursery> houseDetailQueryWrapper =
                                        new QueryWrapper<>();
                                houseDetailQueryWrapper
                                        .lambda()
                                        .eq(EduHouseDetailNursery::getYear, finalYear)
                                        .in(
                                                EduHouseDetailNursery::getRealProperty,
                                                house.getQlrxxList().stream()
                                                        .map(HouseInterfaceDetailVO::getBdcqzh)
                                                        .collect(Collectors.toList()))
                                        .in(
                                                EduHouseDetailNursery::getIdcard,
                                                house.getQlrxxList().stream()
                                                        .map(HouseInterfaceDetailVO::getZjh)
                                                        .collect(Collectors.toList()))
                                        .select(EduHouseDetailNursery::getHouseId);
                                List<String> idList =
                                        eduHouseDetailNurseryService
                                                .list(houseDetailQueryWrapper)
                                                .stream()
                                                .map(EduHouseDetailNursery::getHouseId)
                                                .distinct()
                                                .collect(Collectors.toList());
                                for (int i = 0; i < idList.size(); i++) {
                                    EduHouseNursery oldhouseById =
                                            eduHouseNurseryService.getById(idList.get(i));
                                    if (house.getZl().equals(oldhouseById.getAddress())) {
                                        odlHouse = oldhouseById;
                                    }
                                }
                            } else {
                                houseQueryWrapper
                                        .lambda()
                                        .eq(EduHouseNursery::getRealPropertyNum, house.getBdcdyh())
                                        .eq(EduHouseNursery::getRealProperty, realProperty)
                                        .eq(EduHouseNursery::getYear, finalYear);
                                odlHouse = eduHouseNurseryService.getOne(houseQueryWrapper);
                            }
                            EduHouseNursery eduHouse;
                            if (!ObjectUtils.isEmpty(odlHouse)) {
                                eduHouse = odlHouse;
                            } else {
                                eduHouse = new EduHouseNursery();
                                eduHouse.setHouseId(IdUtil.simpleUUID());
                            }
                            eduHouse.setAddress(house.getZl());
                            if (!ObjectUtils.isEmpty(house.getDjsj())) {
                                eduHouse.setRegisterDate(
                                        DateUtil.parse(house.getDjsj(), "yyyy年MM月dd日"));
                            }
                            if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                                eduHouse.setRealProperty(realProperty);
                            }
                            eduHouse.setRealPropertyNum(house.getBdcdyh());
                            if (!ObjectUtils.isEmpty(house.getTdsyqssj())) {
                                eduHouse.setBegDate(
                                        DateUtil.parse(house.getTdsyqssj(), "yyyy年MM月dd日"));
                            }
                            if (!ObjectUtils.isEmpty(house.getTdsyjssj())) {
                                eduHouse.setEndDate(
                                        DateUtil.parse(house.getTdsyjssj(), "yyyy年MM月dd日"));
                            }
                            String yt = house.getYt().replace("/", "").trim();
                            eduHouse.setLandCategories(
                                    saveDict(
                                            "LANDCATEGORIES", yt, vo.getAccessToken()));
                            eduHouse.setLandCategoriesName(yt);
                            eduHouse.setHouseNature(
                                    saveDict(
                                            "HOUSENATURE", house.getFwxz(), vo.getAccessToken()));
                            eduHouse.setHouseNatureName(house.getFwxz());
                            eduHouse.setYear(finalYear);
                            eduHouse.setStatus("1");
                            eduHouse.setAuthStatus(AuthStatusEnum.NODO.getType());
                            ArrayList<EduHouseDetailNursery> detailList = new ArrayList<>();
                            if (!ObjectUtils.isEmpty(house.getQlrxxList())) {
                                List<HouseInterfaceDetailVO> qlrxxList = house.getQlrxxList();
                                if (!ObjectUtils.isEmpty(house.getTdsyjssj())
                                        && !ObjectUtils.isEmpty(house.getTdsyqssj())) {
                                    int betweenYear =
                                            (int)
                                                    DateUtil.betweenYear(
                                                            DateUtil.offsetDay(
                                                                    DateUtil.parse(
                                                                            house.getTdsyqssj(),
                                                                            "yyyy年MM月dd日"),
                                                                    -1),
                                                            DateUtil.parse(
                                                                    house.getTdsyjssj(),
                                                                    "yyyy年MM月dd日"),
                                                            false);
                                    eduHouse.setYearLimit(betweenYear);
                                } else {
                                    eduHouse.setYearLimit(100);
                                }
                                if (!ObjectUtils.isEmpty(realProperty)
                                        && (realProperty.contains("证明")
                                        || realProperty.contains("预"))) {
                                    eduHouse.setAuthStatus(AuthStatusEnum.YES.getType());
                                    eduHouse.setStatus(BoolEnum.FALSE.getType());
                                }
                                house.getQlrxxList()
                                        .forEach(
                                                qlrxx -> {
                                                    QueryWrapper<EduHouseDetailNursery>
                                                            detailQueryWrapper =
                                                            new QueryWrapper<>();
                                                    detailQueryWrapper
                                                            .lambda()
                                                            .eq(
                                                                    EduHouseDetailNursery
                                                                            ::getRealProperty,
                                                                    qlrxx.getBdcqzh())
                                                            .eq(
                                                                    EduHouseDetailNursery
                                                                            ::getHouseId,
                                                                    eduHouse.getHouseId())
                                                            .eq(
                                                                    EduHouseDetailNursery
                                                                            ::getIdcard,
                                                                    qlrxx.getZjh())
                                                            .eq(
                                                                    EduHouseDetailNursery::getYear,
                                                                    finalYear);
                                                    EduHouseDetailNursery detail;
                                                    EduHouseDetailNursery odlHouseDetail =
                                                            eduHouseDetailNurseryService.getOne(
                                                                    detailQueryWrapper);
                                                    if (!ObjectUtils.isEmpty(odlHouseDetail)) {
                                                        detail = odlHouseDetail;
                                                    } else {
                                                        detail = new EduHouseDetailNursery();
                                                        detail.setHouseDetailId(
                                                                IdUtil.simpleUUID());
                                                    }
                                                    detail.setHouseId(eduHouse.getHouseId());
                                                    detail.setRealProperty(qlrxx.getBdcqzh());
                                                    detail.setIdcard(qlrxx.getZjh());
                                                    detail.setFullName(qlrxx.getQlr());
                                                    detail.setCommonSituation(
                                                            saveDict(
                                                                    "COMMONSITUATION",
                                                                    qlrxx.getGyfs(),
                                                                    vo.getAccessToken()));
                                                    detail.setCommonSituationName(qlrxx.getGyfs());
                                                    detail.setYear(eduHouse.getYear());
                                                    detail.setStatus("1");
                                                    detailList.add(detail);
                                                });
                            }
                            eduHouseNurseryService.saveOrUpdate(eduHouse);
                            eduHouseDetailNurseryService.saveOrUpdateBatch(detailList);
                            eduHouseVOList.add(Convert.convert(EduHouseVO.class, eduHouse));
                        });
            }
        } catch (Exception e) {
            logger.error("房产获取异常"+e.getMessage());
            throw new AppException(e.getMessage());
        }
        return eduHouseVOList;

    }


}
